Esempio n. 1
0
 def setup_environ(self):
     # Set up base environment
     env = self.base_environ = {}
     env['SERVER_NAME'] = to_bytes(self.server_name)
     env['GATEWAY_INTERFACE'] = b'CGI/1.1'
     env['SERVER_PORT'] = to_bytes(str(self.server_port))
     env['REMOTE_HOST'] = b''
     env['CONTENT_LENGTH'] = b''
     env['SCRIPT_NAME'] = b''
Esempio n. 2
0
def demo_app(environ):
    result = b'Hello world!'
    headers = [
        (b'Content-Length', to_bytes(len(result))),
        (b'Content-Type', b'text/plain'),
        ]
    return (b'200 OK', headers, [result])
Esempio n. 3
0
    def get_environ(self):
        env = self.server.base_environ.copy()
        env['SERVER_PROTOCOL'] = to_bytes(self.request_version)
        env['REQUEST_METHOD'] = to_bytes(self.command)
        if '?' in self.path:
            path, query = self.path.split('?', 1)
        else:
            path, query = self.path, ''

        env['PATH_INFO'] = to_bytes(urllib.unquote(path))
        env['RAW_PATH_INFO'] = to_bytes(path)
        env['QUERY_STRING'] = to_bytes(query)

        host = self.address_string()
        if host != self.client_address[0]:
            env['REMOTE_HOST'] = to_bytes(host)
        env['REMOTE_ADDR'] = to_bytes(self.client_address[0])

        typeheader = self.headers.get('content-type')

        if typeheader is None:
            env['CONTENT_TYPE'] = b'text/plain'
        else:
            env['CONTENT_TYPE'] = to_bytes(typeheader)

        length = self.headers.get('content-length')
        if length:
            env['CONTENT_LENGTH'] = to_bytes(length)

        headers = self.headers.items()

        for k, v in headers:
            k = k.replace('-','_').upper()
            v = v.strip()
            if k in env:
                continue                    # skip content length, type,etc.
            if 'HTTP_'+k in env:
                env['HTTP_'+k] += b','+ to_bytes(v) # comma-separate multiples
            else:
                env['HTTP_'+k] = to_bytes(v)
        return env