Spring Boot request header return null valueWhy underscores are forbidden in HTTP header namesproblem using...
Removing disk while game is suspended
Advice for a new journal editor
What does it mean for a caliber to be flat shooting?
speculum - A simple, straightforward Arch Linux mirror list optimizer
Non-Cancer terminal illness that can affect young (age 10-13) girls?
How can i do a custom maintenance message on magento 2.2.4
Spring Boot request header return null value
Why is it that Bernie Sanders is always called a "socialist"?
kill -0 <PID> は何をするのでしょうか?
How did Ancient Greek 'πυρ' become English 'fire?'
Traveling through the asteriod belt?
Cookies - Should the toggles be on?
Can a Pact of the Blade warlock use the correct existing pact magic weapon so it functions as a "Returning" weapon?
Making him into a bully (how to show mild violence)
Is boss over stepping boundary/micromanaging?
Nested word series [humans only]
Can a hotel cancel a confirmed reservation?
Why are the books in the Game of Thrones citadel library shelved spine inwards?
How do you funnel food off a cutting board?
Which one of these password policies are more secure?
Early credit roll before the end of the film
Why zero tolerance on nudity in space?
Can a person refuse a presidential pardon?
What's a good word to describe a public place that looks like it wouldn't be rough?
Spring Boot request header return null value
Why underscores are forbidden in HTTP header namesproblem using UserService of google appengineServlet Flow on a Request via AjaxGwt Controller With Annotation ApproachHow do you set the Content-Type header for an HttpClient request?How to configure port for a Spring Boot applicationRequest parameters are unavailable in servletAngular2-SpringBoot application : “Authorization” request header overridden by SpringBootsymbol: class ServletExceptionKeycloak spring boot microservicesSending JWT Token in the body of response Java Spring
I have a spring boot project which has some Rest APIs in it. I have two custom headers named request_date
and tenant
respectively.
I am trying to read the value of these headers in an interceptor, but it reads the value for only tenant
and returns null for request_date
.
Important
- I use a filter to wrap the request object because I want to read the request body later.
- There is a filter to add CORS headers.
When I run my project on localhost and debug the code, I am successfully able to read both the headers' values.
However, when I deploy my application in production and make the request using postman or some other client, the request_date
header's value is always read as null.
I am not sure what seems to be the problem with this. I am using Spring boot v1.5.10.RELEASE
and JDK 1.8
Note:
- I have tried to rename the header to something like
input_date
. However, it still reads null.
The following is the relevant code
TestInterceptor
public class TestInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String requestDate = request.getHeader("request_date");
String tenant = request.getHeader("Tenant");
/*Perform some checks*/
return super.preHandle(request, response, handler);
}
}
CorsFilter
public class ApiCorsFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, PATCH, OPTIONS, DELETE, PUT");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers," +
" X-Requested-With, Origin, X-Auth-Token, Tenant, request_date");
response.addHeader("Access-Control-Expose-Headers", "X-Auth-Token, Content-Disposition");
chain.doFilter(request, response);
}
}
RequestCacheFilter
public class RequestCacheFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
HttpServletRequest req = new RequestWrapper(request);
String body = ((RequestWrapper) req).getBody();
/*Do some operation*/
filterChain.doFilter(req, response);
}
}
java spring rest spring-boot http
add a comment |
I have a spring boot project which has some Rest APIs in it. I have two custom headers named request_date
and tenant
respectively.
I am trying to read the value of these headers in an interceptor, but it reads the value for only tenant
and returns null for request_date
.
Important
- I use a filter to wrap the request object because I want to read the request body later.
- There is a filter to add CORS headers.
When I run my project on localhost and debug the code, I am successfully able to read both the headers' values.
However, when I deploy my application in production and make the request using postman or some other client, the request_date
header's value is always read as null.
I am not sure what seems to be the problem with this. I am using Spring boot v1.5.10.RELEASE
and JDK 1.8
Note:
- I have tried to rename the header to something like
input_date
. However, it still reads null.
The following is the relevant code
TestInterceptor
public class TestInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String requestDate = request.getHeader("request_date");
String tenant = request.getHeader("Tenant");
/*Perform some checks*/
return super.preHandle(request, response, handler);
}
}
CorsFilter
public class ApiCorsFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, PATCH, OPTIONS, DELETE, PUT");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers," +
" X-Requested-With, Origin, X-Auth-Token, Tenant, request_date");
response.addHeader("Access-Control-Expose-Headers", "X-Auth-Token, Content-Disposition");
chain.doFilter(request, response);
}
}
RequestCacheFilter
public class RequestCacheFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
HttpServletRequest req = new RequestWrapper(request);
String body = ((RequestWrapper) req).getBody();
/*Do some operation*/
filterChain.doFilter(req, response);
}
}
java spring rest spring-boot http
What if you callrequest.getHeaderNames()
? Is it possible that null is set in the missing header?
– StanislavL
2 hours ago
I am not calling request.getHeaderNames(), yet I can read the value of the other headers. The problem is only specific to "request_date" header
– greenPadawan
1 hour ago
add a comment |
I have a spring boot project which has some Rest APIs in it. I have two custom headers named request_date
and tenant
respectively.
I am trying to read the value of these headers in an interceptor, but it reads the value for only tenant
and returns null for request_date
.
Important
- I use a filter to wrap the request object because I want to read the request body later.
- There is a filter to add CORS headers.
When I run my project on localhost and debug the code, I am successfully able to read both the headers' values.
However, when I deploy my application in production and make the request using postman or some other client, the request_date
header's value is always read as null.
I am not sure what seems to be the problem with this. I am using Spring boot v1.5.10.RELEASE
and JDK 1.8
Note:
- I have tried to rename the header to something like
input_date
. However, it still reads null.
The following is the relevant code
TestInterceptor
public class TestInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String requestDate = request.getHeader("request_date");
String tenant = request.getHeader("Tenant");
/*Perform some checks*/
return super.preHandle(request, response, handler);
}
}
CorsFilter
public class ApiCorsFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, PATCH, OPTIONS, DELETE, PUT");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers," +
" X-Requested-With, Origin, X-Auth-Token, Tenant, request_date");
response.addHeader("Access-Control-Expose-Headers", "X-Auth-Token, Content-Disposition");
chain.doFilter(request, response);
}
}
RequestCacheFilter
public class RequestCacheFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
HttpServletRequest req = new RequestWrapper(request);
String body = ((RequestWrapper) req).getBody();
/*Do some operation*/
filterChain.doFilter(req, response);
}
}
java spring rest spring-boot http
I have a spring boot project which has some Rest APIs in it. I have two custom headers named request_date
and tenant
respectively.
I am trying to read the value of these headers in an interceptor, but it reads the value for only tenant
and returns null for request_date
.
Important
- I use a filter to wrap the request object because I want to read the request body later.
- There is a filter to add CORS headers.
When I run my project on localhost and debug the code, I am successfully able to read both the headers' values.
However, when I deploy my application in production and make the request using postman or some other client, the request_date
header's value is always read as null.
I am not sure what seems to be the problem with this. I am using Spring boot v1.5.10.RELEASE
and JDK 1.8
Note:
- I have tried to rename the header to something like
input_date
. However, it still reads null.
The following is the relevant code
TestInterceptor
public class TestInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String requestDate = request.getHeader("request_date");
String tenant = request.getHeader("Tenant");
/*Perform some checks*/
return super.preHandle(request, response, handler);
}
}
CorsFilter
public class ApiCorsFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, PATCH, OPTIONS, DELETE, PUT");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers," +
" X-Requested-With, Origin, X-Auth-Token, Tenant, request_date");
response.addHeader("Access-Control-Expose-Headers", "X-Auth-Token, Content-Disposition");
chain.doFilter(request, response);
}
}
RequestCacheFilter
public class RequestCacheFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
HttpServletRequest req = new RequestWrapper(request);
String body = ((RequestWrapper) req).getBody();
/*Do some operation*/
filterChain.doFilter(req, response);
}
}
java spring rest spring-boot http
java spring rest spring-boot http
edited 1 hour ago
Karol Dowbecki
22.2k93254
22.2k93254
asked 2 hours ago
greenPadawangreenPadawan
7861815
7861815
What if you callrequest.getHeaderNames()
? Is it possible that null is set in the missing header?
– StanislavL
2 hours ago
I am not calling request.getHeaderNames(), yet I can read the value of the other headers. The problem is only specific to "request_date" header
– greenPadawan
1 hour ago
add a comment |
What if you callrequest.getHeaderNames()
? Is it possible that null is set in the missing header?
– StanislavL
2 hours ago
I am not calling request.getHeaderNames(), yet I can read the value of the other headers. The problem is only specific to "request_date" header
– greenPadawan
1 hour ago
What if you call
request.getHeaderNames()
? Is it possible that null is set in the missing header?– StanislavL
2 hours ago
What if you call
request.getHeaderNames()
? Is it possible that null is set in the missing header?– StanislavL
2 hours ago
I am not calling request.getHeaderNames(), yet I can read the value of the other headers. The problem is only specific to "request_date" header
– greenPadawan
1 hour ago
I am not calling request.getHeaderNames(), yet I can read the value of the other headers. The problem is only specific to "request_date" header
– greenPadawan
1 hour ago
add a comment |
2 Answers
2
active
oldest
votes
Some network tools can drop headers that contain underscore in it's name. As per this answer underscore is a legal character but it's uncommon and sometimes tools require additional configuration to support it.
Rename your header to requestDate
or request-date
and see if it helps. If it works without underscore than inspect network route between client and server e.g. maybe there is a proxy that drops them?
add a comment |
The issue was with the nginx configuration.
I set the underscores_in_headers on;
for the server and now it doesn't drop the headers with underscore in their names.
The solution suggested by @Karol Dowbecki works as well. When I renamed my header to requestDate
, I was able to read the value successfully.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54923593%2fspring-boot-request-header-return-null-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Some network tools can drop headers that contain underscore in it's name. As per this answer underscore is a legal character but it's uncommon and sometimes tools require additional configuration to support it.
Rename your header to requestDate
or request-date
and see if it helps. If it works without underscore than inspect network route between client and server e.g. maybe there is a proxy that drops them?
add a comment |
Some network tools can drop headers that contain underscore in it's name. As per this answer underscore is a legal character but it's uncommon and sometimes tools require additional configuration to support it.
Rename your header to requestDate
or request-date
and see if it helps. If it works without underscore than inspect network route between client and server e.g. maybe there is a proxy that drops them?
add a comment |
Some network tools can drop headers that contain underscore in it's name. As per this answer underscore is a legal character but it's uncommon and sometimes tools require additional configuration to support it.
Rename your header to requestDate
or request-date
and see if it helps. If it works without underscore than inspect network route between client and server e.g. maybe there is a proxy that drops them?
Some network tools can drop headers that contain underscore in it's name. As per this answer underscore is a legal character but it's uncommon and sometimes tools require additional configuration to support it.
Rename your header to requestDate
or request-date
and see if it helps. If it works without underscore than inspect network route between client and server e.g. maybe there is a proxy that drops them?
answered 1 hour ago
Karol DowbeckiKarol Dowbecki
22.2k93254
22.2k93254
add a comment |
add a comment |
The issue was with the nginx configuration.
I set the underscores_in_headers on;
for the server and now it doesn't drop the headers with underscore in their names.
The solution suggested by @Karol Dowbecki works as well. When I renamed my header to requestDate
, I was able to read the value successfully.
add a comment |
The issue was with the nginx configuration.
I set the underscores_in_headers on;
for the server and now it doesn't drop the headers with underscore in their names.
The solution suggested by @Karol Dowbecki works as well. When I renamed my header to requestDate
, I was able to read the value successfully.
add a comment |
The issue was with the nginx configuration.
I set the underscores_in_headers on;
for the server and now it doesn't drop the headers with underscore in their names.
The solution suggested by @Karol Dowbecki works as well. When I renamed my header to requestDate
, I was able to read the value successfully.
The issue was with the nginx configuration.
I set the underscores_in_headers on;
for the server and now it doesn't drop the headers with underscore in their names.
The solution suggested by @Karol Dowbecki works as well. When I renamed my header to requestDate
, I was able to read the value successfully.
answered 1 hour ago
greenPadawangreenPadawan
7861815
7861815
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54923593%2fspring-boot-request-header-return-null-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What if you call
request.getHeaderNames()
? Is it possible that null is set in the missing header?– StanislavL
2 hours ago
I am not calling request.getHeaderNames(), yet I can read the value of the other headers. The problem is only specific to "request_date" header
– greenPadawan
1 hour ago