-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix panic when assign to nil header and cookie when host is not found #5401
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
base: master
Are you sure you want to change the base?
Conversation
4d550d8 to
98fb1bf
Compare
|
Hi @chojs23, thanks for the contribution! Can you add a test to reproduce this issue to avoid future regressions?
|
98fb1bf to
10bbb87
Compare
|
Hi @inancgumus, I added some tests. |
inancgumus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the tests. All LGTM but one thing.
| resp := &Response{ | ||
| URL: preq.URL.URL, | ||
| Request: respReq, | ||
| Headers: make(map[string]string), | ||
| Cookies: make(map[string][]*HTTPCookie), | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the NewResponse function here? Other than that, your PR is LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@inancgumus Thanks for review!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually breaking a test because we expect the body to be null here: https://github.com/grafana/k6/blob/master/js/modules/k6/http/request_test.go#L2256 so I think this should be added in both places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chojs23, sure. Can you check @AgnesToulet's suggestion please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@inancgumus Creating Response with NewResponse function initialize body with empty array but this could break TestBinaryResponseWithStatus0 test as @AgnesToulet mentioned.
Hmm, Can we change the initial body null to empty array? I don't know the original code that creating Response with nil body was intended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to keep the original behavior as users could rely on checking if the response body is null in some cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep the original behavior, can you revert the last commit? Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I reverted it.
115af52 to
022acbb
Compare
What?
When a request fails, the Response object is still returned but previously the Headers and Cookies maps were nil.
Why?
Trying to assign to a nil map causes a panic. Now these maps are always initialized, so users can safely modify them even for failed requests.
Checklist
make check) and all pass.Checklist: Documentation (only for k6 maintainers and if relevant)
Please do not merge this PR until the following items are filled out.
Related PR(s)/Issue(s)
Closes #5213