简体   繁体   中英

How do I configure ANY web server to accept POST requests that have No Host and absolute request URIS?

I have a client that sends http requests with absolute request uris and does not define "host"

There for a web server like Jetty rejects the POST request saying:

org.eclipse.jetty.http.BadMessageException: 400: No Host

Is there any way to configure jetty or any other web server to accept post requests that don't have a host?

https://tools.ietf.org/html/rfc7230#section-5.4

A client MUST send a Host header for it to be compliant to HTTP/1.1

If you send an absolute URI in the target, then the Host header must be the same as what is found in that absolute URI target.

Note that the HTTP/1.1 spec even states ...

A server MUST respond with a 400 (Bad Request) status code to any HTTP/1.1 request message that lacks a Host header field and to any request message that contains more than one Host header field or a Host header field with an invalid field-value.

This makes it a requirement to respond with error 400 in this situation, always.

If you use HTTP/2, then you can avoid this because the split between target URI and Host header was addressed with the :authority pseudo-header.

See https://httpwg.org/specs/rfc7540.html#rfc.section.8.1.2.3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM