Search code examples
web-serviceswebserverjetty

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?


Solution

  • https://www.rfc-editor.org/rfc/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