libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] Broken HTTP 1.0 and 0.9 support


From: Geoffrey McRae
Subject: Re: [libmicrohttpd] Broken HTTP 1.0 and 0.9 support
Date: Fri, 23 Apr 2010 09:25:42 +1000

Hi Christian,

Anything pre HTTP 1.0 is considered 0.9, it was never an official RFC,
but is widely implemented. A good example is to telnet to google with a
0.9 response. Apache implements this behaviour, as does IIS and
ligHTTPd.

# tenet google.com 80
> GET /
>
< <html>.........</html>

The 0 bytes is just to return a valid value without a segfault, with no
headers, or \r\n after the end of the headers, the document should just
be appended after.

Returning HTTP/1.1 should be OK, but no other major web-server does it
and it is breaking 1.0 standards, and some HTTP clients get screwed up
when the version is not what was requested. 

Please see RFC1945 page 13:

=====================
HTTP/1.0 servers must:
        ...
        o respond appropriately with a message in the same protocol
        version
        used by the client.
=====================

Also, RFC2145 page 5

=====================
... An HTTP server SHOULD send a response version equal to the highest
version for which the server is at least conditionally compliant, and
whose major version is less than or equal to the one received in the
request. ...
=====================

Kind Regards
Geoff

        
On Thu, 2010-04-22 at 20:58 +0200, Christian Grothoff wrote:
> Hi!
> 
> I'm not sure about both of these.  My reading of the standard (and the 
> principle of being permissive in general) is that if we receive an HTTP 
> request with an "unknown" version number (i.e. 0.9 or 1.2) but we can process 
> it, we should.  Moreover, if your server wants to do something else (say, not 
> return 200 OK), you can (since the version number is exposed to you via the 
> API).
> 
> Similarly, my reading of the standard is that if a client says "HTTP 1.0", it 
> is completely OK to respond "and this server supports HTTP 1.1" as long as no 
> 1.1 features are used otherwise.
> 
> 
> If you have any specific statements in say HTTP RFCs that contradict this, 
> I'll be happy to give your patch strong consideration, but at this point I am 
> not convinced that these changes would actually be an improvement.
> 
> Finally, I am not sure what exactly you're trying to do with the 0-byte 
> response that you create in your patch (close the connection?), but I'm not 
> sure it is the best (=simplest) way to do whatever you want to do.
> 
> My 2 cents
> 
> Christian
> 
> On Wednesday 21 April 2010 03:00:12 pm Geoffrey McRae wrote:
> > Hi All,
> > 
> > I am one of the developers for XBMC where we are using your wonderful
> > library for our web interface. It has come to my attention however that
> > support for HTTP/1.0 and 0.9 is broken/wrong.
> > 
> > Currently 0.9 for requests it serves out an invalid " 200 OK" and the
> > headers, which it should not.
> > 
> > For 1.0 it returns HTTP/1.1 in the response, which again is incorrect
> > since we made a 1.0 request.
> > 
> > The following patch corrects both of these issues.
> > 
> > Kind Regards
> > Geoffrey McRae (gnif)
> > http://www.xbmc.org/
> > 
> > diff --git a/lib/libmicrohttpd/src/daemon/connection.c
> > b/lib/libmicrohttpd/src/daemon/connection.c
> > index ef47b1c..dc71be9 100644
> > --- a/lib/libmicrohttpd/src/daemon/connection.c
> > +++ b/lib/libmicrohttpd/src/daemon/connection.c
> > @@ -577,13 +577,23 @@ build_header_response (struct MHD_Connection
> > *connection)
> >    enum MHD_ValueKind kind;
> >    const char *reason_phrase;
> > 
> > +  if (strlen(connection->version) == 0)
> > +    {
> > +      data = MHD_pool_allocate (connection->pool, 0, MHD_YES);
> > +      connection->write_buffer = data;
> > +      connection->write_buffer_append_offset = 0;
> > +      connection->write_buffer_send_offset = 0;
> > +      connection->write_buffer_size = 0;
> > +      return MHD_YES;
> > +    }
> > +
> >    if (connection->state == MHD_CONNECTION_FOOTERS_RECEIVED)
> >      {
> >        add_extra_headers (connection);
> >        reason_phrase = MHD_get_reason_phrase_for
> > (connection->responseCode);
> >        SPRINTF (code,
> >                 "%s %u %s\r\n",
> > -               MHD_HTTP_VERSION_1_1, connection->responseCode,
> > reason_phrase);
> > +               connection->version, connection->responseCode,
> > reason_phrase);
> >        off = strlen (code);
> >        /* estimate size */
> >        size = off + 2;           /* extra \r\n at the end */
> > 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]