App Engine Application HTTP Status Status Message

I found a mismatch between Java dev_appserver and the Live Engine App server.

On my local development server, I have a Servlet that returns:

 return response.sendError(response.SC_BAD_REQUEST, "Please log in to comment"); 

When I access the page, I return a message with a status code in the header, which:

 Status Code:400 Please log in to comment 

The problem occurs when I deploy this to App Engine. When accessing the same servlet, I get this "bad request" instead of "Please log in to comment":

 Status Code:400 Bad Request 

The status message Please log in to comment Status Code appears in the HTML content, but not in the header, as in the development environment.

Why is this?

Edit

Here's the curl -vvvv trace curl -vvvv for dev_appserver and production:

dev_appserver curl trace:

 > POST /add-comment HTTP/1.1 > User-Agent: Mozilla/4.0 > Host: localhost:8080 > Accept: */* > Content-Length: 9 > Content-Type: application/x-www-form-urlencoded > < HTTP/1.1 400 Please log in to comment < Content-Type: text/html; charset=iso-8859-1 < Cache-Control: must-revalidate,no-cache,no-store < Content-Length: 1406 < Server: Jetty(6.1.x) 

Curl Production Curve:

 > POST /add-comment HTTP/1.1 > User-Agent: Mozilla/4.0 > Host: www.xxx.org > Accept: */* > Content-Length: 9 > Content-Type: application/x-www-form-urlencoded > < HTTP/1.1 400 Bad Request < Content-Type: text/html; charset=utf-8 < Vary: Accept-Encoding < Date: Thu, 18 Aug 2011 14:04:26 GMT < Server: Google Frontend < Cache-Control: private < Transfer-Encoding: chunked 
+4
source share
2 answers

I would say that the prod system is the right implementation. Javadocs for sendError() say:

Sends an error response to the client using the specified state. The server by default creates a response similar to the HTML version of the server error page containing the specified message , setting the content type to "text / html", leaving cookies and other headers unmodified. If a web application was made an error message for a page that matches the status code passed, it will override the preference for the proposed msg parameter.

If the answer has already been completed, this method is IllegalStateException. After using this method, the answer should be considered perfect and should not be written.

I highlighted the part. This says that it simply returns a html message page when possible. He does not say that he uses it in the HTTP status code (which I personally have not seen anywhere :()

+3
source

This is not a problem with sendError . The setStatus method will behave the same. In normal Java, both sendError and setStatus , set a description of the state. The problem is that the App Engine server for production always sets a state description for a standard description for each code.

+1
source

All Articles