D2744: hgweb: handle CONTENT_LENGTH
This revision was automatically updated to reflect the committed changes. Closed by commit rHGed0456fde625: hgweb: handle CONTENT_LENGTH (authored by indygreg, committed by ). REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D2744?vs=6824&id=6899 REVISION DETAIL https://phab.mercurial-scm.org/D2744 AFFECTED FILES mercurial/hgweb/request.py mercurial/wireprotoserver.py CHANGE DETAILS diff --git a/mercurial/wireprotoserver.py b/mercurial/wireprotoserver.py --- a/mercurial/wireprotoserver.py +++ b/mercurial/wireprotoserver.py @@ -91,10 +91,9 @@ return args def forwardpayload(self, fp): -if b'Content-Length' in self._req.headers: -length = int(self._req.headers[b'Content-Length']) -else: -length = int(self._wsgireq.env[r'CONTENT_LENGTH']) +# Existing clients *always* send Content-Length. +length = int(self._req.headers[b'Content-Length']) + # If httppostargs is used, we need to read Content-Length # minus the amount that was consumed by args. length -= int(self._req.headers.get(b'X-HgArgs-Post', 0)) diff --git a/mercurial/hgweb/request.py b/mercurial/hgweb/request.py --- a/mercurial/hgweb/request.py +++ b/mercurial/hgweb/request.py @@ -200,6 +200,13 @@ headers = wsgiheaders.Headers(headers) +# This is kind of a lie because the HTTP header wasn't explicitly +# sent. But for all intents and purposes it should be OK to lie about +# this, since a consumer will either either value to determine how many +# bytes are available to read. +if 'CONTENT_LENGTH' in env and 'HTTP_CONTENT_LENGTH' not in env: +headers['Content-Length'] = env['CONTENT_LENGTH'] + return parsedrequest(url=fullurl, baseurl=baseurl, advertisedurl=advertisedfullurl, advertisedbaseurl=advertisedbaseurl, To: indygreg, #hg-reviewers, durin42 Cc: mharbison72, durin42, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2744: hgweb: handle CONTENT_LENGTH
mharbison72 added inline comments. INLINE COMMENTS > request.py:205 > +# sent. But for all intents and purposes it should be OK to lie about > +# this, since a consumer will either either value to determine how many > +# bytes are available to read. typo: "... will either either value..." REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2744 To: indygreg, #hg-reviewers, durin42 Cc: mharbison72, durin42, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2744: hgweb: handle CONTENT_LENGTH
indygreg updated this revision to Diff 6824. indygreg edited the summary of this revision. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D2744?vs=6750&id=6824 REVISION DETAIL https://phab.mercurial-scm.org/D2744 AFFECTED FILES mercurial/hgweb/request.py mercurial/wireprotoserver.py CHANGE DETAILS diff --git a/mercurial/wireprotoserver.py b/mercurial/wireprotoserver.py --- a/mercurial/wireprotoserver.py +++ b/mercurial/wireprotoserver.py @@ -91,10 +91,9 @@ return args def forwardpayload(self, fp): -if b'Content-Length' in self._req.headers: -length = int(self._req.headers[b'Content-Length']) -else: -length = int(self._wsgireq.env[r'CONTENT_LENGTH']) +# Existing clients *always* send Content-Length. +length = int(self._req.headers[b'Content-Length']) + # If httppostargs is used, we need to read Content-Length # minus the amount that was consumed by args. length -= int(self._req.headers.get(b'X-HgArgs-Post', 0)) diff --git a/mercurial/hgweb/request.py b/mercurial/hgweb/request.py --- a/mercurial/hgweb/request.py +++ b/mercurial/hgweb/request.py @@ -200,6 +200,13 @@ headers = wsgiheaders.Headers(headers) +# This is kind of a lie because the HTTP header wasn't explicitly +# sent. But for all intents and purposes it should be OK to lie about +# this, since a consumer will either either value to determine how many +# bytes are available to read. +if 'CONTENT_LENGTH' in env and 'HTTP_CONTENT_LENGTH' not in env: +headers['Content-Length'] = env['CONTENT_LENGTH'] + return parsedrequest(url=fullurl, baseurl=baseurl, advertisedurl=advertisedfullurl, advertisedbaseurl=advertisedbaseurl, To: indygreg, #hg-reviewers, durin42 Cc: durin42, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2744: hgweb: handle CONTENT_LENGTH
durin42 accepted this revision. durin42 added inline comments. This revision is now accepted and ready to land. INLINE COMMENTS > wireprotoserver.py:94 > def forwardpayload(self, fp): > -if b'Content-Length' in self._req.headers: > -length = int(self._req.headers[b'Content-Length']) > -else: > -length = int(self._wsgireq.env[r'CONTENT_LENGTH']) > +# TODO Content-Length may not always be defined. > +length = int(self._req.headers[b'Content-Length']) For our clients it always will, because we precompute the bundle to a file. It's gross. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2744 To: indygreg, #hg-reviewers, durin42 Cc: durin42, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2744: hgweb: handle CONTENT_LENGTH
indygreg created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY PEP-0333 says CONTENT_LENGTH may be set. I /think/ WSGI servers are allowed to invent this key even if the client didn't send it. We had code in wireprotoserver looking for this key. So let's just automagically convert this key to an HTTP request header when parsing the request. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2744 AFFECTED FILES mercurial/hgweb/request.py mercurial/wireprotoserver.py CHANGE DETAILS diff --git a/mercurial/wireprotoserver.py b/mercurial/wireprotoserver.py --- a/mercurial/wireprotoserver.py +++ b/mercurial/wireprotoserver.py @@ -91,10 +91,9 @@ return args def forwardpayload(self, fp): -if b'Content-Length' in self._req.headers: -length = int(self._req.headers[b'Content-Length']) -else: -length = int(self._wsgireq.env[r'CONTENT_LENGTH']) +# TODO Content-Length may not always be defined. +length = int(self._req.headers[b'Content-Length']) + # If httppostargs is used, we need to read Content-Length # minus the amount that was consumed by args. length -= int(self._req.headers.get(b'X-HgArgs-Post', 0)) diff --git a/mercurial/hgweb/request.py b/mercurial/hgweb/request.py --- a/mercurial/hgweb/request.py +++ b/mercurial/hgweb/request.py @@ -200,6 +200,13 @@ headers = wsgiheaders.Headers(headers) +# This is kind of a lie because the HTTP header wasn't explicitly +# sent. But for all intents and purposes it should be OK to lie about +# this, since a consumer will either either value to determine how many +# bytes are available to read. +if 'CONTENT_LENGTH' in env and 'HTTP_CONTENT_LENGTH' not in env: +headers['Content-Length'] = env['CONTENT_LENGTH'] + return parsedrequest(url=fullurl, baseurl=baseurl, advertisedurl=advertisedfullurl, advertisedbaseurl=advertisedbaseurl, To: indygreg, #hg-reviewers Cc: mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel