I am sending a request to a third-party API, and their server (PHP 5.5) requires that the content-length header be uppercased 'Content-Length'.
However, I'm using Spring webclient, and it is sending out the 'Content-Length' in lowercased 'content-length', however I tried to send it out as uppercased.
webClient
.method(method)
.uri(uri)
.headers(headersConsumer)
.header("Content-Length-Test", Integer.toString(objectMapper.writeValueAsBytes(reqBody).length))
.header("Content-Length", Integer.toString(objectMapper.writeValueAsBytes(reqBody).length))
.bodyValue(Optional.ofNullable(reqBody).orElse(""))
.retrieve()
.bodyToMono(returnType)
result
POST /test/test HTTP/1.1
user-agent: ReactorNetty/1.0.12
Content-Type: application/json
Authorization: Basic
Accept: */*
Host: 127.0.0.1:9999
Content-Length-Test: 202
content-length: 202
You can see that "Content-Length-Test" that I put in prints out as expected, but not for the actual "Content-Length" header.
I've read the following and related posts about how the HTTP standard specifies that all headers are case insensitive.
The problem is the API I need for my service is case-sensitive when it comes to processing headers. How to prevent of converting header name into lower case - Spring boot?
How can I prevent the Content-Length header from being lower cased?
Need help.
Thanks.