bruno icon indicating copy to clipboard operation
bruno copied to clipboard

Response Header Name issue.

Open kap199297 opened this issue 1 year ago • 8 comments

As per the HTTP response headers list, the first letter of the header should be in Capital case but, I am seeing all headers in lowercase in Bruno's response. Please let me know if there config to change the same. Thanks.

image

kap199297 avatar Apr 04 '24 18:04 kap199297

We could add an Option to automatically "prettify" Header names, but the casing for headers does not matter anyway.

https://www.rfc-editor.org/rfc/rfc9110.html#section-5.1 / https://www.rfc-editor.org/rfc/rfc9110.html#section-6.3

Field names are case-insensitive and ought to be registered within the "Hypertext Transfer Protocol (HTTP) Field Name Registry"; see Section 16.3.1.

Its-treason avatar Apr 04 '24 18:04 Its-treason

Oh, this is trippy. I literally just opened #2012 which is quite similar.

I think @Its-treason is right. As HTTP headers are supposed to be case-insensitive anyway, having Bruno always lowercase the header's name is reasonable. It just has to be accounted for when fetching the name with res.getHeader(). My recommendation in #2012 was to update the docs to clearly articulate that.

I don't think we want to prettify header names. We either have to honor what is sent back from the server, or always lowercase it. By lowercasing it, we never have to do a .toLowerCase() on a potentially undefined header name which would throw an exception anyways.

DanaEpp avatar Apr 04 '24 18:04 DanaEpp

I think you're right, changing/"prettifying" the casing of headers, would just cause confusion, so we should just leave everything lowercase.

Its-treason avatar Apr 04 '24 18:04 Its-treason

Yes. I would agree that it is case insensitive. I am new to bruno and I was referring insomnia scripts to get response header. I got undefined for Authorization name but I got correct value for authorization. Just for curiousity, is there any provision where it should return same response header for Authorization and authorization based on case insensitive logic 🤔

kap199297 avatar Apr 04 '24 19:04 kap199297

I don't think there is an official provision, other than the HTTP spec saying headers are case-insensitive. Our library (axios) just lowercases all header names. But we should clarify this in the documentation.

Its-treason avatar Apr 04 '24 19:04 Its-treason

How about

class BrunoResponse {

  // ...

  getHeader(name) {
    return this.res && this.res.headers ? (this.res.headers[name] || this.res.headers[name.toLowerCase()]) : null;
  }

  // ...
}

or even

class BrunoResponse {

  // ...

  getHeader(name) {
    return this.res && this.res.headers ? this.res.headers[name.toLowerCase()] : null;
  }

  // ...
}

if it is guaranteed that axios will always lower case the header names?

lanthoor avatar Apr 06 '24 07:04 lanthoor

This would be great suggestion and it will resolve the problem of script migration from postman/insomnia to bruno. 👍

kap199297 avatar Apr 06 '24 17:04 kap199297

@lanthoor Axios always lowercases the header names: https://axios-http.com/docs/res_schema

sebimarkgraf avatar Apr 09 '24 05:04 sebimarkgraf