[PATCH 1 of 2] hgweb: add support for 100-continue as recommended by PEP 333
Augie Fackler
durin42 at gmail.com
Sat Oct 9 13:28:00 UTC 2010
# HG changeset patch
# User Augie Fackler <durin42 at gmail.com>
# Date 1265452048 21600
# Node ID eabfcde6ea8b7df7245a0d51bcad7dfcf430a474
# Parent 7178f6fedb9db000300abda8168d36a890a686c2
hgweb: add support for 100-continue as recommended by PEP 333.
diff --git a/mercurial/hgweb/common.py b/mercurial/hgweb/common.py
--- a/mercurial/hgweb/common.py
+++ b/mercurial/hgweb/common.py
@@ -79,6 +79,23 @@
else:
self.message = _statusmessage(code)
+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
diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py
+++ b/mercurial/hgweb/server.py
@@ -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):
@@ -106,6 +107,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,
diff --git a/mercurial/hgweb/wsgicgi.py b/mercurial/hgweb/wsgicgi.py
--- a/mercurial/hgweb/wsgicgi.py
+++ b/mercurial/hgweb/wsgicgi.py
@@ -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,6 +24,11 @@
if environ['PATH_INFO'].startswith(scriptname):
environ['PATH_INFO'] = environ['PATH_INFO'][len(scriptname):]
+ # Not sure if this is correct
+ stdin = sys.stdin
+ if environ.get('HTTP_EXPECT', '').lower() == '100-continue':
+ stdin = common.continuereader(stdin, sys.stdout.write)
+
environ['wsgi.input'] = sys.stdin
environ['wsgi.errors'] = sys.stderr
environ['wsgi.version'] = (1, 0)
More information about the Mercurial-devel
mailing list