-
Notifications
You must be signed in to change notification settings - Fork 186
STRF-13001 - Add Method for Retrieving All Response Headers Including Duplicates #301
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
Conversation
d1c4dc7
to
73b6776
Compare
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.
@bc-jz I see that there are some other then cookies duplicate headers. E.g. content-type. So my question is it possible we have the same header with different values? Why this is happening (non cookies duplicated)?
I see what you mean about other duplicates.....maybe I need to clear this list of headers between requests. Let me see what happens if I do. |
Good callout! The results look a lot better by clearing the property during the |
src/Bigcommerce/Api/Connection.php
Outdated
|
||
/** | ||
* @var array<string, string> Hash of headers from HTTP response | ||
* @var array<string, string> Hash of headers from HTTP response. Will overwrite cookies with duplicates keys. |
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.
really this is valid for any header, not just cookies.
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.
Ah good point. I'll update the comment.
src/Bigcommerce/Api/Connection.php
Outdated
} else { | ||
$trimHeader = trim($headers); | ||
if (!empty($trimHeader)) { | ||
$this->responseHeadersList[] = $trimHeader; |
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.
🤔 do we want to classify them by key? something like:
$this->responseHeaderList[$key][] = $value;
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.
We could. What I plan to do with them is iterate through looking for the Set-Cookie
that has the XSRF-TOKEN
. I suppose that is a little more performant if we have already filtered by the $key
.
Do you think it is worth the extra complication here?
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.
not worried about performance here, we don't expect 3000 headers 😅
just exposing an api that makes sense, considering the other api is arranged by header type, I was thinking it might be worth keeping the API similar.
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 don't mind either way really 🤷
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.
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.
if you expect a single entry, shouldn't you use the other method? 🤔
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.
Good point. You could and if by some chance there is multiple then it would be available here.
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.
Updated pr. 👍
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.
Defining type was griefing me but got it going now 😅
3b34722
to
0d8ec02
Compare
… returning a list of all response headers, including headers with duplicate keys.
What?
Add a
getHeadersList()
method to theConnection
class to allow returning a list of all response headers, including headers with duplicate keys.The existing
getHeaders()
method and process for generating those headers will overwrite response headers that share the same key name leaving only the last one. This has become a problem in many of our tests where we depend on theSet-Cookie
response header to retrieve anXSRF-TOKEN
cookie. We have found that responses with multipleSet-Cookie
response headers are not reliably making theXSRF-TOKEN
cookie available as it gets overwritten by anotherSet-Cookie
header.This change is meant to be additive and not alter the output of any existing methods.
Tickets / Documentation
Screenshots (if appropriate)
Here is a live example of the difference between the results of the existing headers collection (


responseHeaders
) and this new headers collection (responseHeadersList
). Note theresponseHeaders
only has less than the full list of headers:^ You can also see that
responseHeadersList
shows multipleSet-Cookie
response headers. This is what this PR is intending to add.