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

Accept Header Issue #12

Open
cpheps opened this issue Apr 9, 2018 · 4 comments
Open

Accept Header Issue #12

cpheps opened this issue Apr 9, 2018 · 4 comments

Comments

@cpheps
Copy link

cpheps commented Apr 9, 2018

I've run into an issue when using the DownloadReleaseAsset function in the github.com/google/go-github library. It appears the GitHub API will not correctly download a release asset binary when two Accept headers are present.

Transport.RoundTrip adds it's own Accept header which causes the download to fail as the API is looking for a single header with the value application/octet-stream.

Here is the link the the GitHub API documentation https://developer.github.com/v3/repos/releases/#get-a-single-release-asset

@lyonlai
Copy link

lyonlai commented Apr 18, 2021

@cpheps yo. I saw you had the PR and it's closed eventually. how did you solve it at the end? using your own folk?

@cpheps
Copy link
Author

cpheps commented Apr 18, 2021

@lyonlai That's was a few years and jobs. We didn't fork it but I seem to remember somehow rebuilding the headers from scratch and deleting the extra accept header.

@lyonlai
Copy link

lyonlai commented Apr 19, 2021

sigh. this should be merged. we ended up feeding a custom Transport to overwritre the header just for the download URL, which fits our use case but still not ideal as could be fixed in this library. Thanks for answering, it's just for curiosity. @cpheps

@elgohr
Copy link

elgohr commented Feb 22, 2022

Using something like

type downloadingRoundTripper struct {
	roundTripper http.RoundTripper
}

func NewDownloadingRoundTripper() *downloadingRoundTripper {
	return &downloadingRoundTripper{roundTripper: http.DefaultTransport}
}

func (r *downloadingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
	if req.Method == http.MethodGet && strings.Contains(req.URL.Path, "/releases/assets/") {
		req.Header.Set("Accept", "application/octet-stream")
	}
	return r.roundTripper.RoundTrip(req)
}

as the default roundtripper could be a workaround/ugly fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants