-
Notifications
You must be signed in to change notification settings - Fork 28
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
http.Response.Body() closed in Do() regardless of value of v
#4
Comments
Thanks for contributing back! The behaviour here needs to be carefully added. Since responses are always returned, they should either always require closing, or always not require closing. Otherwise the code in callers requires an if condition making it verbose. The assumption of the client was that if the body was required it would always be parsed into the correct struct. What is your use case where this is not true? |
From looking at the Golang http docs
So the behaviour you have requested seems standard. However, this will require cutting a new major release which is why I just wanted to confirm when the response body is required. I use the lib in a terraform provider and only have the request so I can check the status code for some errors. |
Hi @dillon-giacoppo, thank you for the quick reply! For context, I am pulling a non-json-encoded file down from Artifactory. Per the godocs of the
So it sounded like the body should be readable from the returned response (and as you mentioned, is pretty standard). I'll get around it for the time being by passing in a |
I have been passing in an io.Writer myself which I realise might be an anti-pattern. I will include your changes in the next v2 release which has support for the new API. Whats the endpoint this is for? It feels like this is something the client should handle itself, are you using the client to actually download artefacts? I would most definitely use the official artifactory cli for that. This library was designed to cover the gaps in "meta" configuration i.e creating repos. It was unintended that the client would be directly accessed so I would be keen to add support for what you are trying to do and ideally mark the client as internal. |
Yes, I'm downloading artifacts via a script to verify test coverage in a CI pipeline. I'll poke around the JFrog client then if I'm using this in an unintended way. Thanks for the help! |
Describe the bug
In attempting to read the response body from the return
http.Response
fromclient.Do()
whenv
isnil
, the following error is received:http2: response body closed
To Reproduce
Steps to reproduce the behavior:
artifactory.NewClient("artifactory url", nil)
)client.NewRequest(http.MethodGet, "path", nil)
)client.Do(ctx, request, nil)
)Expected behavior
A readable
response.Body
that has yet to be closed.The text was updated successfully, but these errors were encountered: