8000 Response is not-nil if error is nil by alexandear · Pull Request #376 · aerokube/ggr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Response is not-nil if error is nil #376

Merged
merged 1 commit into from
Feb 27, 2023
Merged

Response is not-nil if error is nil #376

merged 1 commit into from
Feb 27, 2023

Conversation

alexandear
Copy link
Contributor
@alexandear alexandear commented Feb 23, 2023

This PR removes if resp != nil check when creating a session in proxy.go.

The resp object cannot be nil in this code, as it is assigned the return value of httpClient.Do(req) method call, which returns a non-nil response object or an `error if the request could not be sent or the server returns an error response. From the documentation:

If the returned error is nil, the Response will contain a non-nil Body which the user is expected to close.
...
The request Body, if non-nil, will be closed by the underlying Transport, even on errors.

Actually, the code has leaked resources, but in proxy_test.go. Every call to http.Get must be accompanied by rsp.Body.Close() call. These places can be found by bodyclose linter.

@vania-pooh
Copy link
Member

@alexandear correct, but let's just do defer resp.Body.Close() after err != nil check. Logging is not needed here.

@alexandear
Copy link
Contributor Author

@vania-pooh done

@vania-pooh vania-pooh merged commit 914ace9 into aerokube:master Feb 27, 2023
@vania-pooh
Copy link
Member

@alexandear thank you for contribution.

@alexandear alexandear deleted the resp-is-not-nil branch February 27, 2023 17:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0