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

Collsion in response and request headers #281

Open
Norbytus opened this issue Oct 10, 2024 · 7 comments
Open

Collsion in response and request headers #281

Norbytus opened this issue Oct 10, 2024 · 7 comments
Assignees
Labels
bug Something isn't working invalid This doesn't seem right question Further information is requested

Comments

@Norbytus
Copy link

If response or request have header with same name, response.headers.valuesOf('Header name') return last header

@gorillamoe gorillamoe added the bug Something isn't working label Oct 10, 2024
@gorillamoe gorillamoe self-assigned this Oct 10, 2024
@gorillamoe
Copy link
Member

gorillamoe commented Oct 14, 2024

Can you give me an example on this?

Because it works as intended, afaik:

# @name REQUEST_FOOBAR
POST https://httpbin.org/post HTTP/1.1
Date: Foobar

{
  "foo": "bonobo",
  "foobar": true
}

> {%
client.log(request.headers.findByName("Date").getRawValue());
client.log(response.headers.valuesOf("Date").value);
%}

This outputs:

Foobar
Mon, 14 Oct 2024 01:27:03 GMT

The first one is the header from the request and the second one the header from the response.

@gorillamoe gorillamoe added question Further information is requested invalid This doesn't seem right labels Oct 14, 2024
@Norbytus
Copy link
Author

Its more i wrote wrong description,
For example you have in response or request headers like

HTTP/1.1 200 OK
Cache-Control: no-cache, private
Content-Type: application/json
Set-Cookie: Access-Token=value
Set-Cookie: Refresh-Token=value
Vary: Accept-Encoding
Transfer-Encoding: chunked

When i try get access to header you get last one
response.headers.valuesOf('Set-Cookie')

@Grueslayer
Copy link
Contributor

RFC 2616 says it is possible to send multiple values in separate header lines only when it is possible to also combine the values by comma in one header line. Currently it is not supported in Kulala.

Some implementation always return an array, some will combine these to a comma separated list (which I think is the only solution to have backward compatibility)

@Norbytus
Copy link
Author

In jetbrains it's looks like

 response.headers.valuesOf('Set-Cookie').forEach(function (value) {/*... */}

@gorillamoe
Copy link
Member

In jetbrains it's looks like

 response.headers.valuesOf('Set-Cookie').forEach(function (value) {/*... */}

Will try in jetbrains and see if we can implement it in kulala.

@Grueslayer
Copy link
Contributor

Grueslayer commented Oct 14, 2024

What is the result when there is only one occurrence? A string (so the caller has to check the result type) or an array with one element (that would be a breaking change in scripts).

we need to decide what we do with the Request Variables: vscode-rest-client returns the first one.

As RFC defines all implementations must accept both forms maybe we return the comma list at least in Request Variables.

if you test against JetBrains please also check if they deliver an array if given as list in one header.

@Norbytus
Copy link
Author

I don't use JetBrains, but my college use like this
JetBrains doc https://www.jetbrains.com/help/idea/http-response-reference.html#headers-reference

 response.headers.valuesOf('Set-Cookie').forEach(function (value) {
        const parts = value.split('=');
        const settings = parts[1].split(';');

        if (parts[0] === 'First_Variant') {
/* ... */
        }

        if (parts[0] === 'Second_Varoant') {
/* .. */
        }
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working invalid This doesn't seem right question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants