Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring not setting statusText on response

I am using some 3rd party stuff that is requiring the statusText on the response to be set. No matter what I do, it is just "". I am using Spring 4.3.4 and Spring Boot 1.4.2.

I tried having the HttpServletResponse as a parameter in my controller method and then call sendError like this:

public void foo(@PathVariable String myVar, HttpServletResponse response) throws IOException
{
  //... other stuff
  response.sendError(200, "OKOKOKOKOK");
}

However, when the actual response comes back to the browser, the response looks like this:

{"timestamp":1486068130749,"status":200,"error":"OK","message":"OKOKOKOKOK","path":"/my/path"}

And the statusText is still "". I know Spring must be generating this response before sending back to the client. How can I prevent this? Is there some way I can get a non empty string set for the statusText?

like image 362
dnc253 Avatar asked Oct 21 '25 07:10

dnc253


1 Answers

I think you must be referring to the HTTP status line sent by the Servlet container. As of Tomcat 8.5, the HTTP reason phrase is not written anymore, since it's not required and should not be read by HTTP clients: See this Spring Boot issue for more details.

like image 56
Brian Clozel Avatar answered Oct 22 '25 23:10

Brian Clozel