title: web.py: Get the original web request
body: <p>I need to access to the original http request that the browser send to the server in <code>web.py</code>.</p>
  
  <p>E.g., this is the request that Chromium issues when I surf to some page:</p>
  
  <pre><code>$ nc -l 8081
  GET / HTTP/1.1
  Host: 127.0.0.1:8081
  Connection: keep-alive
  Cache-Control: max-age=0
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.22 (KHTML, like Gecko) Ubuntu Chromium/25.0.1364.160 Chrome/25.0.1364.160 Safari/537.22
  Accept-Encoding: gzip,deflate,sdch
  Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4
  Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
  </code></pre>
  
  <p>I tried to get that from the <a href="http://webpy.org/cookbook/ctx" rel="nofollow"><code>web.ctx.env</code></a>, but that's a dictionary (while I'd prefer the original raw text request) and it's mixed with some other data:</p>
  
  <pre><code>SERVER_SOFTWARE: CherryPy/3.2.0 Server
  SCRIPT_NAME: 
  ACTUAL_SERVER_PROTOCOL: HTTP/1.1
  REQUEST_METHOD: GET
  PATH_INFO: /
  SERVER_PROTOCOL: HTTP/1.1
  QUERY_STRING: 
  HTTP_ACCEPT_CHARSET: ISO-8859-1,utf-8;q=0.7,*;q=0.3
  HTTP_USER_AGENT: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.22 (KHTML, like Gecko) Ubuntu Chromium/25.0.1364.160 Chrome/25.0.1364.160 Safari/537.22
  HTTP_CONNECTION: keep-alive
  REMOTE_PORT: 55409
  SERVER_NAME: localhost
  REMOTE_ADDR: 127.0.0.1
  wsgi.url_scheme: http
  SERVER_PORT: 8081
  wsgi.input: &lt;web.wsgiserver.KnownLengthRFile object at 0x940b16c&gt;
  HTTP_HOST: 127.0.0.1:8081
  wsgi.multithread: True
  REQUEST_URI: /
  HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  wsgi.version: (1, 0)
  wsgi.run_once: False
  wsgi.errors: &lt;open file '&lt;stderr&gt;', mode 'w' at 0xb73010d0&gt;
  wsgi.multiprocess: False
  HTTP_ACCEPT_LANGUAGE: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4
  HTTP_ACCEPT_ENCODING: gzip,deflate,sdch
  </code></pre>
  
  <p>This is the code I used to obtain the output above:</p>
  
  <pre><code>#!/usr/bin/env python
  
  import web
  
  urls = ('(.*)', 'urlhandler')
  
  class urlhandler:
    def GET(self, url):
      txt = ""
      for k, v in web.ctx.env.items():
        txt += ": ".join([k, str(v)]) + "\n"
      return txt
  
  if __name__ == '__main__':
    app = web.application(urls, globals())
    app.run()
  </code></pre>
  
  <p>Should I purge this dictionary from unwanted data or is there a straightforward way to get the original request?</p>