From http-wg-request@cuckoo.hpl.hp.com  Tue Jun 20 12:57:05 2000
Received: from atlrel1.hp.com (atlrel1.hp.com [156.153.255.210])
	by ietf.org (8.9.1a/8.9.1a) with ESMTP id MAA28863
	for <http-archive@odin.ietf.org>; Tue, 20 Jun 2000 12:57:05 -0400 (EDT)
Received: from l3107mxr.atl.hp.com (l3107mxr.atl.hp.com [15.19.254.19])
	by atlrel1.hp.com (Postfix) with ESMTP
	id 5E610281; Tue, 20 Jun 2000 12:57:01 -0400 (EDT)
Received: from otter.hpl.hp.com (otter.hpl.hp.com [15.144.59.2])
	by l3107mxr.atl.hp.com (Postfix) with ESMTP
	id CBB554FD9E; Tue, 20 Jun 2000 11:56:23 -0400 (EDT)
Received: from cuckoo.hpl.hp.com (cuckoo.hpl.hp.com [15.144.30.127])
	by otter.hpl.hp.com (8.9.3/HP-Labs Bristol Internal Mail Hub) with ESMTP id RAA06937;
	Tue, 20 Jun 2000 17:56:22 +0100 (BST)
Received: (from procmail@localhost) by cuckoo.hpl.hp.com (8.7.6/8.7.3 TIS 5.0) id RAA18284; Tue, 20 Jun 2000 17:56:13 +0100 (BST)
Resent-Date: Tue, 20 Jun 2000 17:56:13 +0100 (BST)
X-Lotus-FromDomain: NEON
From: "Brad Taylor" <btaylor@neonsys.com>
To: http-wg@cuckoo.hpl.hp.com
Message-ID: <86256904.005CF854.00@internet1.neonsys.com>
Date: Tue, 20 Jun 2000 11:55:00 -0500
Subject: Re: subscribe
Mime-Version: 1.0
Content-type: text/plain; charset=us-ascii
Content-Disposition: inline
Resent-Message-ID: <"EERwH3.0.fT4.j8wJv"@cuckoo>
Resent-From: http-wg@cuckoo.hpl.hp.com
X-Mailing-List: <http-wg@cuckoo.hpl.hp.com> archive/latest/800
X-Loop: http-wg@cuckoo.hpl.hp.com
Precedence: list
Resent-Sender: http-wg-request@cuckoo.hpl.hp.com




06/20/2000 11:55 AM
Brad Taylor@NEON
Brad Taylor@NEON
Brad Taylor@NEON
06/20/2000 11:55 AM
06/20/2000 11:55 AM

We are having a debate on browser behaviour and are trying to find what the
official spec says.  What we see is that browsers (ie5.0 and netscape) when
"POST"ing to our server construct a content-length and then append a 0d0a
to the end.  This 0d0a is not contained in the content length.  Is this
according to "SPEC"?  If so would someone be so kind as to point it out (I
am somewhat new to reading these specs).  Is this only going to occur for
POSTed data or will it also occur for other requests (GET, PUT,
etc.)....your consideration in advance is appreciated.




From http-wg-request@cuckoo.hpl.hp.com  Tue Jun 20 12:59:01 2000
Received: from atlrel1.hp.com (atlrel1.hp.com [156.153.255.210])
	by ietf.org (8.9.1a/8.9.1a) with ESMTP id MAA29170
	for <http-archive@odin.ietf.org>; Tue, 20 Jun 2000 12:59:01 -0400 (EDT)
Received: from l3107mxr.atl.hp.com (l3107mxr.atl.hp.com [15.19.254.19])
	by atlrel1.hp.com (Postfix) with ESMTP
	id D7AEC620; Tue, 20 Jun 2000 12:59:00 -0400 (EDT)
Received: from otter.hpl.hp.com (otter.hpl.hp.com [15.144.59.2])
	by l3107mxr.atl.hp.com (Postfix) with ESMTP
	id F0ED64FD98; Tue, 20 Jun 2000 11:58:51 -0400 (EDT)
Received: from cuckoo.hpl.hp.com (cuckoo.hpl.hp.com [15.144.30.127])
	by otter.hpl.hp.com (8.9.3/HP-Labs Bristol Internal Mail Hub) with ESMTP id RAA07134;
	Tue, 20 Jun 2000 17:58:49 +0100 (BST)
Received: (from procmail@localhost) by cuckoo.hpl.hp.com (8.7.6/8.7.3 TIS 5.0) id RAA18384; Tue, 20 Jun 2000 17:58:47 +0100 (BST)
Resent-Date: Tue, 20 Jun 2000 17:58:47 +0100 (BST)
X-Lotus-FromDomain: NEON
From: "Brad Taylor" <btaylor@neonsys.com>
To: http-wg@cuckoo.hpl.hp.com
Message-ID: <86256904.005D34CA.00@internet1.neonsys.com>
Date: Tue, 20 Jun 2000 11:57:35 -0500
Subject: CRLF on POST requests, where/how specified (repost from prior bad
	 subject line)
Mime-Version: 1.0
Content-type: text/plain; charset=us-ascii
Content-Disposition: inline
Resent-Message-ID: <"dDSoC3.0.DV4.7BwJv"@cuckoo>
Resent-From: http-wg@cuckoo.hpl.hp.com
X-Mailing-List: <http-wg@cuckoo.hpl.hp.com> archive/latest/801
X-Loop: http-wg@cuckoo.hpl.hp.com
Precedence: list
Resent-Sender: http-wg-request@cuckoo.hpl.hp.com




06/20/2000 11:57 AM
Brad Taylor@NEON
Brad Taylor@NEON
Brad Taylor@NEON
06/20/2000 11:57 AM
06/20/2000 11:57 AM

We are having a debate on browser behaviour and are trying to find what the
official spec says.  What we see is that browsers (ie5.0 and netscape) when
"POST"ing to our server construct a content-length and then append a 0d0a
to the end.  This 0d0a is not contained in the content length.  Is this
according to "SPEC"?  If so would someone be so kind as to point it out (I
am somewhat new to reading these specs).  Is this only going to occur for
POSTed data or will it also occur for other requests (GET, PUT,
etc.)....your consideration in advance is appreciated.




From http-wg-request@cuckoo.hpl.hp.com  Tue Jun 20 13:40:47 2000
Received: from atlrel2.hp.com (atlrel2.hp.com [156.153.255.202])
	by ietf.org (8.9.1a/8.9.1a) with ESMTP id NAA00275
	for <http-archive@odin.ietf.org>; Tue, 20 Jun 2000 13:40:47 -0400 (EDT)
Received: from l3107mxr.atl.hp.com (l3107mxr.atl.hp.com [15.19.254.19])
	by atlrel2.hp.com (Postfix) with ESMTP
	id E968CC52; Tue, 20 Jun 2000 13:40:45 -0400 (EDT)
Received: from otter.hpl.hp.com (otter.hpl.hp.com [15.144.59.2])
	by l3107mxr.atl.hp.com (Postfix) with ESMTP
	id 6F1834FD88; Tue, 20 Jun 2000 12:40:36 -0400 (EDT)
Received: from cuckoo.hpl.hp.com (cuckoo.hpl.hp.com [15.144.30.127])
	by otter.hpl.hp.com (8.9.3/HP-Labs Bristol Internal Mail Hub) with ESMTP id SAA09536;
	Tue, 20 Jun 2000 18:40:34 +0100 (BST)
Received: (from procmail@localhost) by cuckoo.hpl.hp.com (8.7.6/8.7.3 TIS 5.0) id SAA18982; Tue, 20 Jun 2000 18:40:32 +0100 (BST)
Resent-Date: Tue, 20 Jun 2000 18:40:32 +0100 (BST)
From: "Scott Lawrence" <lawrence@agranat.com>
To: "Brad Taylor" <btaylor@neonsys.com>, <http-wg@cuckoo.hpl.hp.com>
Subject: RE: CRLF on POST requests, where/how specified (repost from prior bad subject line)
Date: Tue, 20 Jun 2000 13:36:45 -0400
Message-ID: <005301bfdade$1a760400$954768c0@oyster.agranat.com>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0
In-Reply-To: <86256904.005D34CA.00@internet1.neonsys.com>
X-Mimeole: Produced By Microsoft MimeOLE V4.72.3110.3
Importance: Normal
Resent-Message-ID: <"iG4hA3.0.We4.FowJv"@cuckoo>
Resent-From: http-wg@cuckoo.hpl.hp.com
X-Mailing-List: <http-wg@cuckoo.hpl.hp.com> archive/latest/802
X-Loop: http-wg@cuckoo.hpl.hp.com
Precedence: list
Resent-Sender: http-wg-request@cuckoo.hpl.hp.com
Content-Transfer-Encoding: 7bit


See RFC 2616 ( http://www.innosoft.com/rfc/rfc2616.html#sec-4.1 )

Quoting:

----
Request (section 5) and Response (section 6) messages use the
generic message format of RFC 822 [9] for transferring entities (the
payload of the message). Both types of message consist of a
start-line, zero or more header fields (also known as "headers"), an
empty line (i.e., a line with nothing preceding the CRLF) indicating
the end of the header fields, and possibly a message-body.


        generic-message = start-line
                          *(message-header CRLF)
                          CRLF
                          [ message-body ]
----
The CRLF that separates the headers from the body is not part of
either.  Since it is not part of the body, it is not included in the
content length.

--
Scott Lawrence      Director of R & D        <lawrence@agranat.com>
Agranat Systems   Embedded Web Technology   http://www.agranat.com/



From http-wg-request@cuckoo.hpl.hp.com  Tue Jun 20 13:52:42 2000
Received: from atlrel1.hp.com (atlrel1.hp.com [156.153.255.210])
	by ietf.org (8.9.1a/8.9.1a) with ESMTP id NAA00449
	for <http-archive@odin.ietf.org>; Tue, 20 Jun 2000 13:52:41 -0400 (EDT)
Received: from l3107mxr.atl.hp.com (l3107mxr.atl.hp.com [15.19.254.19])
	by atlrel1.hp.com (Postfix) with ESMTP
	id 430875A2; Tue, 20 Jun 2000 13:52:41 -0400 (EDT)
Received: from otter.hpl.hp.com (otter.hpl.hp.com [15.144.59.2])
	by l3107mxr.atl.hp.com (Postfix) with ESMTP
	id A87114FD88; Tue, 20 Jun 2000 12:52:32 -0400 (EDT)
Received: from cuckoo.hpl.hp.com (cuckoo.hpl.hp.com [15.144.30.127])
	by otter.hpl.hp.com (8.9.3/HP-Labs Bristol Internal Mail Hub) with ESMTP id SAA10851;
	Tue, 20 Jun 2000 18:52:31 +0100 (BST)
Received: (from procmail@localhost) by cuckoo.hpl.hp.com (8.7.6/8.7.3 TIS 5.0) id SAA19272; Tue, 20 Jun 2000 18:52:28 +0100 (BST)
Resent-Date: Tue, 20 Jun 2000 18:52:28 +0100 (BST)
X-Lotus-FromDomain: NEON
From: "Fred Bohle" <fbohle@neonsys.com>
To: http-wg@cuckoo.hpl.hp.com
Message-ID: <86256904.00621F0F.00@internet1.neonsys.com>
Date: Tue, 20 Jun 2000 12:51:11 -0500
Subject: RE: CRLF on POST requests, where/how specified (repost from prior
	 bad subject line)
Mime-Version: 1.0
Content-type: text/plain; charset=us-ascii
Content-Disposition: inline
Resent-Message-ID: <"FV1Fl2.0.5j4.SzwJv"@cuckoo>
Resent-From: http-wg@cuckoo.hpl.hp.com
X-Mailing-List: <http-wg@cuckoo.hpl.hp.com> archive/latest/803
X-Loop: http-wg@cuckoo.hpl.hp.com
Precedence: list
Resent-Sender: http-wg-request@cuckoo.hpl.hp.com





Fred Bohle@NEON
06/20/2000 12:51 PM

Scott,

     No, not the CRLF between the headers and the body.  We are asking
about a
CRLF that follows the body.  It does not seem to be in the 1.0 spec, and
the 1.1 spec
seems to specifically prohibit it.  And yet, IE5 and Netscape both will
send a CRLF
after the body for Content-type: application/x-www-url-encoded.

     What do other web servers do to handle this CRLF?  We find that if we
decide to
close the connection with the end of the response we generate, (Connection:
close)
and THEN the CRLF arrives from the client, the TCP layer will generate a
Reset packet.
This causes (IE5 at least) the client to fail processing the response we
just sent.  So the
application stops, dead in the water.



Fred Bohle





"Scott Lawrence" <lawrence@agranat.com> on 06/20/2000 12:36:45 PM

To:   Brad Taylor/Neon, http-wg@cuckoo.hpl.hp.com
cc:    (bcc: Fred Bohle/Dev/Neon)

Subject:  RE: CRLF on POST requests, where/how specified (repost from prior
      bad subject line)





See RFC 2616 ( http://www.innosoft.com/rfc/rfc2616.html#sec-4.1 )

Quoting:

----
Request (section 5) and Response (section 6) messages use the
generic message format of RFC 822 [9] for transferring entities (the
payload of the message). Both types of message consist of a
start-line, zero or more header fields (also known as "headers"), an
empty line (i.e., a line with nothing preceding the CRLF) indicating
the end of the header fields, and possibly a message-body.


        generic-message = start-line
                          *(message-header CRLF)
                          CRLF
                          [ message-body ]
----
The CRLF that separates the headers from the body is not part of
either.  Since it is not part of the body, it is not included in the
content length.

--
Scott Lawrence      Director of R & D        <lawrence@agranat.com>
Agranat Systems   Embedded Web Technology   http://www.agranat.com/







From http-wg-request@cuckoo.hpl.hp.com  Tue Jun 20 14:13:38 2000
Received: from atlrel2.hp.com (atlrel2.hp.com [156.153.255.202])
	by ietf.org (8.9.1a/8.9.1a) with ESMTP id OAA00884
	for <http-archive@odin.ietf.org>; Tue, 20 Jun 2000 14:13:37 -0400 (EDT)
Received: from l3107mxr.atl.hp.com (l3107mxr.atl.hp.com [15.19.254.19])
	by atlrel2.hp.com (Postfix) with ESMTP
	id B1A982F10; Tue, 20 Jun 2000 14:13:37 -0400 (EDT)
Received: from otter.hpl.hp.com (otter.hpl.hp.com [15.144.59.2])
	by l3107mxr.atl.hp.com (Postfix) with ESMTP
	id 692454FD8B; Tue, 20 Jun 2000 13:13:27 -0400 (EDT)
Received: from cuckoo.hpl.hp.com (cuckoo.hpl.hp.com [15.144.30.127])
	by otter.hpl.hp.com (8.9.3/HP-Labs Bristol Internal Mail Hub) with ESMTP id TAA11554;
	Tue, 20 Jun 2000 19:13:25 +0100 (BST)
Received: (from procmail@localhost) by cuckoo.hpl.hp.com (8.7.6/8.7.3 TIS 5.0) id TAA19573; Tue, 20 Jun 2000 19:13:23 +0100 (BST)
Resent-Date: Tue, 20 Jun 2000 19:13:23 +0100 (BST)
Date: Tue, 20 Jun 2000 14:11:52 -0400 (EDT)
From: Dave Kristol <dmk@research.bell-labs.com>
Message-Id: <200006201811.OAA20241@aleatory.research.bell-labs.com>
To: btaylor@neonsys.com
Subject: Re: CRLF on POST requests, where/how specified (repost from prior bad subject line)
Cc: http-wg@cuckoo.hpl.hp.com
Resent-Message-ID: <"G9kjF3.0.mn4.3HxJv"@cuckoo>
Resent-From: http-wg@cuckoo.hpl.hp.com
X-Mailing-List: <http-wg@cuckoo.hpl.hp.com> archive/latest/804
X-Loop: http-wg@cuckoo.hpl.hp.com
Precedence: list
Resent-Sender: http-wg-request@cuckoo.hpl.hp.com

"Brad Taylor" <btaylor@neonsys.com> wrote:
  > 
  > 
  > 
  > 06/20/2000 11:57 AM
  > Brad Taylor@NEON
  > Brad Taylor@NEON
  > Brad Taylor@NEON
  > 06/20/2000 11:57 AM
  > 06/20/2000 11:57 AM
  > 
  > We are having a debate on browser behaviour and are trying to find what the
  > official spec says.  What we see is that browsers (ie5.0 and netscape) when
  > "POST"ing to our server construct a content-length and then append a 0d0a
  > to the end.  This 0d0a is not contained in the content length.  Is this
  > according to "SPEC"?  If so would someone be so kind as to point it out (I
  > am somewhat new to reading these specs).  Is this only going to occur for
  > POSTed data or will it also occur for other requests (GET, PUT,
  > etc.)....your consideration in advance is appreciated.

IIRC, early in HTTP/1.1 development there were servers that balked if
they received the message body associated with POST but the body didn't
end with a CRLF.  Or maybe it was that some clients erroneously sent
CRLF after every POST body.  Either way, RFC 2616 added the following
words (Sect. 4.1):

   In the interest of robustness, servers SHOULD ignore any empty
   line(s) received where a Request-Line is expected. In other words, if
   the server is reading the protocol stream at the beginning of a
   message and receives a CRLF first, it should ignore the CRLF.

The idea was that if there were pipelined requests, or multiple requests
on a persistent connection, the server should eat the extra CRLFs.

Dave Kristol



From http-wg-request@cuckoo.hpl.hp.com  Tue Jun 20 14:25:12 2000
Received: from atlrel2.hp.com (atlrel2.hp.com [156.153.255.202])
	by ietf.org (8.9.1a/8.9.1a) with ESMTP id OAA01053
	for <http-archive@odin.ietf.org>; Tue, 20 Jun 2000 14:25:12 -0400 (EDT)
Received: from l3107mxr.atl.hp.com (l3107mxr.atl.hp.com [15.19.254.19])
	by atlrel2.hp.com (Postfix) with ESMTP
	id 85345402; Tue, 20 Jun 2000 14:25:09 -0400 (EDT)
Received: from otter.hpl.hp.com (otter.hpl.hp.com [15.144.59.2])
	by l3107mxr.atl.hp.com (Postfix) with ESMTP
	id D72674FD85; Tue, 20 Jun 2000 13:25:00 -0400 (EDT)
Received: from cuckoo.hpl.hp.com (cuckoo.hpl.hp.com [15.144.30.127])
	by otter.hpl.hp.com (8.9.3/HP-Labs Bristol Internal Mail Hub) with ESMTP id TAA12863;
	Tue, 20 Jun 2000 19:24:59 +0100 (BST)
Received: (from procmail@localhost) by cuckoo.hpl.hp.com (8.7.6/8.7.3 TIS 5.0) id TAA19824; Tue, 20 Jun 2000 19:24:57 +0100 (BST)
Resent-Date: Tue, 20 Jun 2000 19:24:57 +0100 (BST)
Date: Tue, 20 Jun 2000 11:21:07 -0700
From: "Life is hard, and then you die" <ronald@innovation.ch>
To: Fred Bohle <fbohle@neonsys.com>
Cc: http-wg@cuckoo.hpl.hp.com
Subject: Re: CRLF on POST requests, where/how specified (repost from prior bad subject line)
Message-ID: <20000620112107.A23741@innovation.ch>
Mail-Followup-To: Fred Bohle <fbohle@neonsys.com>,
	http-wg@cuckoo.hpl.hp.com
References: <86256904.00621F0F.00@internet1.neonsys.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Mailer: Mutt 1.0.1i
In-Reply-To: <86256904.00621F0F.00@internet1.neonsys.com>; from fbohle@neonsys.com on Tue, Jun 20, 2000 at 12:51:11PM -0500
Resent-Message-ID: <"NAUlE2.0.jr4.vRxJv"@cuckoo>
Resent-From: http-wg@cuckoo.hpl.hp.com
X-Mailing-List: <http-wg@cuckoo.hpl.hp.com> archive/latest/805
X-Loop: http-wg@cuckoo.hpl.hp.com
Precedence: list
Resent-Sender: http-wg-request@cuckoo.hpl.hp.com

On Tue, Jun 20, 2000 at 12:51:11PM -0500, Fred Bohle wrote:
> 
>      No, not the CRLF between the headers and the body.  We are asking
>      about a CRLF that follows the body.  It does not seem to be in
>      the 1.0 spec, and the 1.1 spec seems to specifically prohibit it.
>      And yet, IE5 and Netscape both will send a CRLF after the body
>      for Content-type: application/x-www-url-encoded.

The spec clearly disallows this extra CRLF, i.e. it's a bug in those
browsers. However, there is an easy workaround which many people use:
when reading the request line, ignore all whitespace (or empty lines)
until you hit the actual request line.

>      What do other web servers do to handle this CRLF?  We find that
>      if we decide to close the connection with the end of the response
>      we generate, (Connection: close) and THEN the CRLF arrives from
>      the client, the TCP layer will generate a Reset packet.  This
>      causes (IE5 at least) the client to fail processing the response
>      we just sent.  So the application stops, dead in the water.

This is a little tricky, but not much. Basically you need to do a
shutdown on the socket, i.e. only close for sends; then you keep
reading from the socket (and just discard the data) until either you get
an EOF (in which case the client did the close), or until some timeout
(a few seconds) in case the client doesn't close the connection. Note
that this problem is a general problem (i.e. not limited to the extra
CRLF), because you can get the same effect when a client pipelines
requests.


  Cheers,

  Ronald


P.S. take a look at the Apache source: read_request_line() in http_protocol.c
     for the first problem, and lingering_close() in http_main.c for
     the second - the comments are enlightening.



From http-wg-request@cuckoo.hpl.hp.com  Tue Jun 20 15:10:00 2000
Received: from atlrel2.hp.com (atlrel2.hp.com [156.153.255.202])
	by ietf.org (8.9.1a/8.9.1a) with ESMTP id PAA01845
	for <http-archive@odin.ietf.org>; Tue, 20 Jun 2000 15:09:59 -0400 (EDT)
Received: from l3107mxr.atl.hp.com (l3107mxr.atl.hp.com [15.19.254.19])
	by atlrel2.hp.com (Postfix) with ESMTP
	id 0A3B2140E; Tue, 20 Jun 2000 15:09:56 -0400 (EDT)
Received: from otter.hpl.hp.com (otter.hpl.hp.com [15.144.59.2])
	by l3107mxr.atl.hp.com (Postfix) with ESMTP
	id 2ABFD4FD8B; Tue, 20 Jun 2000 14:09:46 -0400 (EDT)
Received: from cuckoo.hpl.hp.com (cuckoo.hpl.hp.com [15.144.30.127])
	by otter.hpl.hp.com (8.9.3/HP-Labs Bristol Internal Mail Hub) with ESMTP id UAA15095;
	Tue, 20 Jun 2000 20:09:44 +0100 (BST)
Received: (from procmail@localhost) by cuckoo.hpl.hp.com (8.7.6/8.7.3 TIS 5.0) id UAA20253; Tue, 20 Jun 2000 20:09:42 +0100 (BST)
Resent-Date: Tue, 20 Jun 2000 20:09:42 +0100 (BST)
X-Lotus-FromDomain: NEON
From: "Brad Taylor" <btaylor@neonsys.com>
To: "Life is hard, and then you die" <ronald@innovation.ch>
Cc: "Fred Bohle" <fbohle@neonsys.com>, http-wg@cuckoo.hpl.hp.com
Message-ID: <86256904.006931C1.00@internet1.neonsys.com>
Date: Tue, 20 Jun 2000 14:08:30 -0500
Subject: apache source included....Re: CRLF on POST requests, where/how
	 specified (repost from prior bad subject line)
Mime-Version: 1.0
Content-type: text/plain; charset=us-ascii
Content-Disposition: inline
Resent-Message-ID: <"n_rMp.0.Qy4.s5yJv"@cuckoo>
Resent-From: http-wg@cuckoo.hpl.hp.com
X-Mailing-List: <http-wg@cuckoo.hpl.hp.com> archive/latest/806
X-Loop: http-wg@cuckoo.hpl.hp.com
Precedence: list
Resent-Sender: http-wg-request@cuckoo.hpl.hp.com




06/20/2000 02:08 PM
Brad Taylor@NEON
Brad Taylor@NEON
Brad Taylor@NEON
06/20/2000 02:08 PM
06/20/2000 02:08 PM



/*
 * More machine-dependent networking gooo... on some systems,
 * you've got to be *really* sure that all the packets are acknowledged
 * before closing the connection, since the client will not be able
 * to see the last response if their TCP buffer is flushed by a RST
 * packet from us, which is what the server's TCP stack will send
 * if it receives any request data after closing the connection.
 *
 * In an ideal world, this function would be accomplished by simply
 * setting the socket option SO_LINGER and handling it within the
 * server's TCP stack while the process continues on to the next request.
 * Unfortunately, it seems that most (if not all) operating systems
 * block the server process on close() when SO_LINGER is used.
 * For those that don't, see USE_SO_LINGER below.  For the rest,
 * we have created a home-brew lingering_close.
 *
 * Many operating systems tend to block, puke, or otherwise mishandle
 * calls to shutdown only half of the connection.  You should define
 * NO_LINGCLOSE in ap_config.h if such is the case for your system.
 */
#ifndef MAX_SECS_TO_LINGER
#define MAX_SECS_TO_LINGER 30
#ifndef NO_LINGCLOSE

/* Special version of timeout for lingering_close */

static void lingerout(int sig)
{
#ifdef NETWARE
    get_tsd
#endif
    if (alarms_blocked) {
     alarm_pending = 1;
     return;
    }

    if (!current_conn) {
     ap_longjmp(jmpbuffer, 1);
    }
    ap_bsetflag(current_conn->client, B_EOUT, 1);
    current_conn->aborted = 1;
}

static void linger_timeout(void)
{
#ifdef NETWARE
    get_tsd
#endif
    timeout_name = "lingering close";
    ap_set_callback_and_alarm(lingerout, MAX_SECS_TO_LINGER);
}

/* Since many clients will abort a connection instead of closing it,
 * attempting to log an error message from this routine will only
 * confuse the webmaster.  There doesn't seem to be any portable way to
 * distinguish between a dropped connection and something that might be
 * worth logging.
 */
static void lingering_close(request_rec *r)
{
    char dummybuf[512];
    struct timeval tv;
    fd_set lfds;
    int select_rv;
    int lsd;

    /* Prevent a slow-drip client from holding us here indefinitely */

    linger_timeout();

    /* Send any leftover data to the client, but never try to again */

    if (ap_bflush(r->connection->client) == -1) {
     ap_kill_timeout(r);
     ap_bclose(r->connection->client);
     return;
    }
    ap_bsetflag(r->connection->client, B_EOUT, 1);

    /* Close our half of the connection --- send the client a FIN */

    lsd = r->connection->client->fd;

    if ((shutdown(lsd, 1) != 0) || r->connection->aborted) {
     ap_kill_timeout(r);
     ap_bclose(r->connection->client);
     return;
    }

    /* Set up to wait for readable data on socket... */

    FD_ZERO(&lfds);

    /* Wait for readable data or error condition on socket;
     * slurp up any data that arrives...  We exit when we go for an
     * interval of tv length without getting any more data, get an error
     * from select(), get an error or EOF on a read, or the timer expires.
     */

    do {
     /* We use a 2 second timeout because current (Feb 97) browsers
      * fail to close a connection after the server closes it.  Thus,
      * to avoid keeping the child busy, we are only lingering long enough
      * for a client that is actively sending data on a connection.
      * This should be sufficient unless the connection is massively
      * losing packets, in which case we might have missed the RST anyway.
      * These parameters are reset on each pass, since they might be
      * changed by select.
      */
#ifdef NETWARE
        ThreadSwitch();
#endif

     FD_SET(lsd, &lfds);
     tv.tv_sec = 2;
     tv.tv_usec = 0;

     select_rv = ap_select(lsd + 1, &lfds, NULL, NULL, &tv);

    } while ((select_rv > 0) &&
             (read(lsd, dummybuf, sizeof dummybuf) > 0));

    /* Should now have seen final ack.  Safe to finally kill socket */

    ap_bclose(r->connection->client);

    ap_kill_timeout(r);
}
#endif /* ndef NO_LINGCLOSE */




"Life is hard, and then you die" <ronald@innovation.ch> on 06/20/2000
01:21:07 PM

To:   Fred Bohle/Dev/Neon
cc:   http-wg@cuckoo.hpl.hp.com (bcc: Brad Taylor/Neon)

Subject:  Re: CRLF on POST requests, where/how specified (repost from prior
      bad subject line)




On Tue, Jun 20, 2000 at 12:51:11PM -0500, Fred Bohle wrote:
>
>      No, not the CRLF between the headers and the body.  We are asking
>      about a CRLF that follows the body.  It does not seem to be in
>      the 1.0 spec, and the 1.1 spec seems to specifically prohibit it.
>      And yet, IE5 and Netscape both will send a CRLF after the body
>      for Content-type: application/x-www-url-encoded.

The spec clearly disallows this extra CRLF, i.e. it's a bug in those
browsers. However, there is an easy workaround which many people use:
when reading the request line, ignore all whitespace (or empty lines)
until you hit the actual request line.

>      What do other web servers do to handle this CRLF?  We find that
>      if we decide to close the connection with the end of the response
>      we generate, (Connection: close) and THEN the CRLF arrives from
>      the client, the TCP layer will generate a Reset packet.  This
>      causes (IE5 at least) the client to fail processing the response
>      we just sent.  So the application stops, dead in the water.

This is a little tricky, but not much. Basically you need to do a
shutdown on the socket, i.e. only close for sends; then you keep
reading from the socket (and just discard the data) until either you get
an EOF (in which case the client did the close), or until some timeout
(a few seconds) in case the client doesn't close the connection. Note
that this problem is a general problem (i.e. not limited to the extra
CRLF), because you can get the same effect when a client pipelines
requests.


  Cheers,

  Ronald


P.S. take a look at the Apache source: read_request_line() in
http_protocol.c
     for the first problem, and lingering_close() in http_main.c for
     the second - the comments are enlightening.







