Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resources.GetRemote HEAD method errors with unexpected EOF #10604

Closed
jmooring opened this issue Jan 5, 2023 · 7 comments
Closed

resources.GetRemote HEAD method errors with unexpected EOF #10604

jmooring opened this issue Jan 5, 2023 · 7 comments
Assignees
Milestone

Comments

@jmooring
Copy link
Member

jmooring commented Jan 5, 2023

Reference: https://discourse.gohugo.io/t/42272/3

When I do this:

{{ $url := "https://gohugo.io/img/hugo.png" }}
{{ $opts := dict "method" "head" }}
{{ with resources.GetRemote $url $opts }}
  {{ with .Err }}
    {{ errorf "Unable to get remote resource: %s" . }}
  {{ else }}
    {{ .Content }}
  {{ end }}
{{ else }}
  {{ errorf "Unable to get remote resource: %s" $url }}
{{ end }}

I get:

Unable to get remote resource: error calling resources.GetRemote: failed to read remote resource “https://gohugo.io/img/hugo.png”: unexpected EOF

But the response is captured and cached in:
/tmp/hugo_cache/my-project/filecache/getresource/6247740232174893946

@bep bep removed the NeedsTriage label Jan 5, 2023
@bep bep added this to the v0.109.0 milestone Jan 5, 2023
@jmooring
Copy link
Member Author

jmooring commented Jan 6, 2023

cc: @vanbroup

@vanbroup
Copy link
Contributor

vanbroup commented Jan 6, 2023

A quick code scan, we should check if the response body is nil bore reading it, as a HEAD response doesn't contain a body.

https://github.com/gohugoio/hugo/blob/master/resources/resource_factories/create/remote.go#L138

should check if res.Body is nil.

I can create a PR to fix and test this next week.

@bep bep self-assigned this Jan 16, 2023
@bep
Copy link
Member

bep commented Jan 16, 2023

should check if res.Body is nil.

I'm checking this now and in @jmooring 's test case the body is not nil, ContentLength is reported as 18210, yet Go is throwing this unexpected EOF error.

@bep
Copy link
Member

bep commented Jan 16, 2023

OK, the Mozilla docs are useful here:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD

image

So, the correct way to handle this is to just ignore the body when the method is HEAD. I will create a pull request.

@bep
Copy link
Member

bep commented Jan 16, 2023

... but that said, I don't see the value of a Resource object from a HEAD request without the ContentLength etc. response info ... I'll see if I can add that to the mix. We have a .Data map that we could stuff this info in.

bep added a commit to bep/hugo that referenced this issue Jan 16, 2023
@bep bep closed this as completed in f13531e Jan 16, 2023
@oclero
Copy link

oclero commented Jan 28, 2023

🥳

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants