does having a space in the http post headers result in BAD request??

I see this in one of the requests: Content-Type "text/xml; c harset=utf-8"

and I get a HTTP/1.1 400 Bad Request

But if the same request is posted with Content-Type "text/xml; charset=utf-8"

i.e no space in charset it works.

In my implementation I am not doing any validation. So I am assuming my Jetty server throws a bad request since there is a space in charset??

Am I right or is my interpretation wrong.

Thanks!!

有帮助吗?

解决方案

Yes, having a space where you are putting it should result in a bad request.

HTTP 1.1 is a protocol defined by a standard. By referencing the standard documentation, it is possible to determine what is and what isn't a valid request.

You can find the standard for HTTP/1.1 at RFC 2616 - Hypertext Transfer Protocol -- HTTP/1.1, and you might specifically want to look at sections 14.17 Content-Type and 3.7 Media Types.

Essentially, by inserting the space into "charset", you are creating an invalid HTTP request because the protocol doesn't understand the "c" and "harset" portions. Those aren't defined as valid text in that context.

Moreover, while the protocol knows what appears to be valid and what doesn't, it isn't intelligent enough to infer how to fix even a simple typo like this. As such, for the server to respond "400 Bad Request" is appropriate and conforming to the protocol standard. For what it's worth, you'll also find the HTTP status codes in the RFC. Status code 400 Bad Request means:

The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.

i.e. Don't do that. :)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top