( )⚙ D2734 hgweb: parse WSGI request into a data structure

This is an archive of the discontinued Mercurial Phabricator instance.

hgweb: parse WSGI request into a data structure
ClosedPublic

Authored by indygreg on Mar 8 2018, 8:06 PM.

Details

Summary

Currently, our WSGI applications (hgweb_mod and hgwebdir_mod) process
the raw WSGI request instance themselves. This means they have to
talk in terms of system strings. And they need to know details
about what's in the WSGI request. And in the case of hgweb_mod, it
is doing some very funky things with URL parsing to impact
dispatching. The code is difficult to read and maintain.

This commit introduces parsing of the WSGI request into a higher-level
and easier-to-reason-about data structure.

To prove it works, we hook it up to hgweb_mod and use it for populating
the relative URL on the request instance.

We hold off on using it in more places because the logic in hgweb_mod
is crazy and I don't want to involve those changes with review of
the parsing code.

The URL construction code has variations that use the HTTP: Host header
(the canonical WSGI way of reconstructing the URL) and with the use
of SERVER_NAME. We need to differentiate because hgweb is currently
using SERVER_NAME for URL construction.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

indygreg created this revision.Mar 8 2018, 8:06 PM
durin42 accepted this revision.Mar 9 2018, 1:59 PM
This revision is now accepted and ready to land.Mar 9 2018, 1:59 PM
This revision was automatically updated to reflect the committed changes.
yuja added a subscriber: yuja.Mar 10 2018, 4:23 AM
yuja added inline comments.
mercurial/hgweb/hgwebdir_mod.py
232

We'll need something to silence pyflakes saying "local variable 'req' is
assigned to but never used."

mercurial/hgweb/request.py
125

Missed assignment fullurl = ?

pulkit added a subscriber: pulkit.Mar 10 2018, 4:45 AM
pulkit added inline comments.
mercurial/hgweb/request.py
14

Chunk from your wip?

indygreg added inline comments.Mar 10 2018, 1:18 PM
mercurial/hgweb/request.py
14

Yes. But there is a TODO below to track enabling it. I fully intend to enable this once we can. That will likely require doing away with the REPO_NAME hack in hgwebdir. That will likely happen towards the end of this series. I'm a few hours away from getting there I think :)

indygreg marked 4 inline comments as done.Mar 10 2018, 1:22 PM

I amended hg-committed with the fixes for the issues @yuja found.