3

I am developing a java based web application in spring-boot where I am sending http-header from server to client end.

Server-side I have used Spring-boot in form of REST API, whereas at client end we have simple plain HTML5/Angular framework.

My query is, while I am sending any header from server then at client end I always get it into lowercase vs actual. For example, I am setting header something like,

header.add("KK-ACTUAL-VALUE", "sfsfjDFFDHTsdfJKKA");

At client end, it gives,

kk-actual-value : "sfsfjDFFDHTsdfJKKA"; (Header name converts into lower case!)

Now, the question is, how to prevent it ?

I want to have the same header name what is actually passed by Server/API.

Vishal Gajera
  • 3,981
  • 4
  • 25
  • 53
  • Header names should be case insensitive, does it matter ? https://stackoverflow.com/questions/5258977/are-http-headers-case-sensitive – user7294900 Mar 14 '19 at 08:49
  • 1
    As request headers should be, by protocol definition, case insensitive, I don't think it's a good solution to design your app behaviour against it. – Matteo Baldi Mar 14 '19 at 08:50
  • @MatteoBaldi that's right. but there is a specific requirement where I need to implement it. – Vishal Gajera Mar 14 '19 at 08:52
  • @user7294900 I know this is quite odd requirement but this is what I get & need to implement it somehow. – Vishal Gajera Mar 14 '19 at 08:54
  • I am adding custom headers to my response and Spring boot doesn't convert headers to lowercase in my case. Have you checked response headers by making API call from tools like Postman? – Harshit Mar 14 '19 at 09:03
  • `header.add("KK-ACTUAL-VALUE", "sfsfjDFFDHTsdfJKKA");` - which exact class is header? – Selaron Mar 14 '19 at 09:25

2 Answers2

5

Looks like tomcat container turns the headers to lowercase. Since spring boot uses an embedded tomcat is been affected by it. More info here: https://github.com/mitre/HTTP-Proxy-Servlet/issues/65

As the Http standard specifies:

Each header field consists of a case-insensitive field name followed by a colon (":") ...

https://www.rfc-editor.org/rfc/rfc7230#section-3.2

Community
  • 1
  • 1
Marco Capo
  • 176
  • 2
  • 7
0

To make the header case-sensitive you can set it to the MultiValueMap, and then pass it as a parameter to the HttpHeaders constructor.

The code snippet can be something like this:

 MultiValueMap <String, String> headers = new LinkedMultiValueMap<>();
    headers.add("KK-ACTUAL-VALUE", "sfsfjDFFDHTsdfJKKA");
    HttpHeaders responseHeaders = new HttpHeaders(headers);

enter image description here

Ivan Polovyi
  • 56
  • 1
  • 3