[issue1491] BaseHTTPServer incorrectly implements response code 100

samwyse report at bugs.python.org
Sun May 11 04:01:38 CEST 2008


samwyse <samwyse at gmail.com> added the comment:

Although any given implementation of an HTTP server is likely to serve
up its headers in a predicable, repeatable, order, I don't think that
we should specify a particular order in the test suite.  Section 4.2
of RFC 2616 specifically states, "The order in which header fields
with differing field names are received is not significant."  So, I
dislike these (and similar) statements in the patch:

+        self.assertTrue(result[1].startswith('Server: '))
+        self.assertTrue(result[2].startswith('Date: '))
+        self.assertTrue(result[3].startswith('Content-Type: '))

I think it would be better to say this:

+        self.assertEqual(sum(r.startswith('Server: ') for r in
result[1:-1]), 1)
+        self.assertEqual(sum(r.startswith('Date: ') for r in result[1:-1]), 1)
+        self.assertEqual(sum(r.startswith('Content-Type: ') for r in
result[1:-1]), 1)

or even this:

+        # Verify that certain message headers occur exactly once.
+        for fieldName in 'Server: ', 'Date: ', 'Content-Type: ':
+            self.assertEqual(sum(r.startswith(fieldName) for r in
result[1:-1]), 1)

(Note that in test_with_continue_1_1, you'd need to say result[2:-1].)

On Sat, May 10, 2008 at 2:34 PM, Jeremy Thurgood <report at bugs.python.org> wrote:
>
> Jeremy Thurgood <firxen at gmail.com> added the comment:
>
> Added handling for "Expect: 100-continue" header to
> BaseHTTPRequestHandler. By default, any request that has this header
> gets a 100 Continue response (with no other headers) before
> do_WHATEVER() is called. By overriding handle_expect_100(), you can
> reject incoming requests instead of sending a 100 Continue if you so desire.
>
> Refactoring as per comments above was also performed.
>
> Note: This patch changes the default behaviour in the case where both
> the client and the server claim to support HTTP/1.1 from doing nothing
> in the case of an "Expect: 100-continue" header on the request to
> sending a 100 Continue response and then completing the request as normal.
>
> ----------
> keywords: +patch
> nosy: +jerith
> Added file: http://bugs.python.org/file10269/BaseHTTPServer_continue.patch
>
> __________________________________
> Tracker <report at bugs.python.org>
> <http://bugs.python.org/issue1491>
> __________________________________
>

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1491>
__________________________________


More information about the Python-bugs-list mailing list