From 4e62b229833022ab485da27079ec535ac3a57bc7 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 25 Aug 2012 08:59:49 -0400 Subject: [PATCH] Add DOCUMENT_URI to scgi-test.py. --- posts/SCGI/scgi-test.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/posts/SCGI/scgi-test.py b/posts/SCGI/scgi-test.py index ee75387..e521f53 100755 --- a/posts/SCGI/scgi-test.py +++ b/posts/SCGI/scgi-test.py @@ -20,6 +20,7 @@ """ import socket as _socket +import urlparse as _urlparse __version__ = '0.1' @@ -46,11 +47,37 @@ def header(method, uri, data=None): content_length = len(data) except TypeError: content_length = 0 + # From RFC 2616, section 5.1.2: + # REQUEST_URI is hex-encoded absolute path + # From Nginx HttpCoreModule docs: + # $document_uri + # The same as $uri. + # $request_uri + # This variable is equal to the *original* request URI as + # received from the client including the args. It cannot be + # modified. Look at $uri for the post-rewrite/altered + # URI. Does not include host name. Example: + # "/foo/bar.php?arg=baz" + # $uri + # This variable is the current request URI, without any + # arguments (see $args for those). This variable will reflect + # any modifications done so far by internal redirects or the + # index module. Note this may be different from $request_uri, + # as $request_uri is what was originally sent by the browser + # before any such modifications. Does not include the protocol + # or host name. Example: /foo/bar.html + scheme,netloc,path,params,query,fragment = _urlparse.urlparse(uri) + # :///;?# + scheme = netloc = '' + request_uri = _urlparse.urlunparse( + (scheme, netloc, path, params, query, fragment)) + document_uri = path strings = [ 'CONTENT_LENGTH\x00{}\x00'.format(content_length), 'SCGI\x00{}\x00'.format(1), 'REQUEST_METHOD\x00{}\x00'.format(method), - 'REQUEST_URI\x00{}\x00'.format(uri), + 'REQUEST_URI\x00{}\x00'.format(request_uri), + 'DOCUMENT_URI\x00{}\x00'.format(document_uri), ] return ''.join(strings) -- 2.26.2