hgweb: add support for 100-continue as recommended by PEP 333.
authorAugie Fackler <durin42@gmail.com>
Sat, 06 Feb 2010 04:27:28 -0600
changeset 13570 617a87cb7eb2
parent 13569 3ab3b892d223
child 13571 84bd3fd63afc
hgweb: add support for 100-continue as recommended by PEP 333.
mercurial/hgweb/common.py
mercurial/hgweb/server.py
mercurial/hgweb/wsgicgi.py
--- a/mercurial/hgweb/common.py	Tue Mar 08 15:36:56 2011 -0500
+++ b/mercurial/hgweb/common.py	Sat Feb 06 04:27:28 2010 -0600
@@ -78,6 +78,23 @@
         self.message = message
         self.headers = headers
 
+class continuereader(object):
+    def __init__(self, f, write):
+        self.f = f
+        self._write = write
+        self.continued = False
+
+    def read(self, amt=-1):
+        if not self.continued:
+            self.continued = True
+            self._write('HTTP/1.1 100 Continue\r\n\r\n')
+        return self.f.read(amt)
+
+    def __getattr__(self, attr):
+        if attr in ('close', 'readline', 'readlines', '__iter__'):
+            return getattr(self.f, attr)
+        raise AttributeError()
+
 def _statusmessage(code):
     from BaseHTTPServer import BaseHTTPRequestHandler
     responses = BaseHTTPRequestHandler.responses
--- a/mercurial/hgweb/server.py	Tue Mar 08 15:36:56 2011 -0500
+++ b/mercurial/hgweb/server.py	Sat Feb 06 04:27:28 2010 -0600
@@ -8,6 +8,7 @@
 
 import os, sys, errno, urllib, BaseHTTPServer, socket, SocketServer, traceback
 from mercurial import util, error
+from mercurial.hgweb import common
 from mercurial.i18n import _
 
 def _splitURI(uri):
@@ -111,6 +112,9 @@
         env['SERVER_PROTOCOL'] = self.request_version
         env['wsgi.version'] = (1, 0)
         env['wsgi.url_scheme'] = self.url_scheme
+        if env.get('HTTP_EXPECT', '').lower() == '100-continue':
+            self.rfile = common.continuereader(self.rfile, self.wfile.write)
+
         env['wsgi.input'] = self.rfile
         env['wsgi.errors'] = _error_logger(self)
         env['wsgi.multithread'] = isinstance(self.server,
--- a/mercurial/hgweb/wsgicgi.py	Tue Mar 08 15:36:56 2011 -0500
+++ b/mercurial/hgweb/wsgicgi.py	Sat Feb 06 04:27:28 2010 -0600
@@ -10,6 +10,7 @@
 
 import os, sys
 from mercurial import util
+from mercurial.hgweb import common
 
 def launch(application):
     util.set_binary(sys.stdin)
@@ -23,7 +24,11 @@
         if environ['PATH_INFO'].startswith(scriptname):
             environ['PATH_INFO'] = environ['PATH_INFO'][len(scriptname):]
 
-    environ['wsgi.input'] = sys.stdin
+    stdin = sys.stdin
+    if environ.get('HTTP_EXPECT', '').lower() == '100-continue':
+        stdin = common.continuereader(stdin, sys.stdout.write)
+
+    environ['wsgi.input'] = stdin
     environ['wsgi.errors'] = sys.stderr
     environ['wsgi.version'] = (1, 0)
     environ['wsgi.multithread'] = False