Esempio n. 1
0
def get_headers(environ: WSGIEnviron) -> http.Headers:
    header_items = []
    for key, value in environ.items():
        if key.startswith('HTTP_'):
            header = (key[5:].lower().replace('_', '-'), value)
            header_items.append(header)
        elif key in ('CONTENT_TYPE', 'CONTENT_LENGTH'):
            header = (key.lower().replace('_', '-'), value)
            header_items.append(header)
    return http.Headers(header_items)
Esempio n. 2
0
def get_request_data(environ: WSGIEnviron):
    if not bool(environ.get('CONTENT_TYPE')):
        mimetype = None
    else:
        mimetype, _ = parse_options_header(environ['CONTENT_TYPE'])

    if mimetype is None:
        value = None
    elif mimetype == 'application/json':
        body = get_input_stream(environ).read()
        value = json.loads(body.decode('utf-8'))
    elif mimetype in ('multipart/form-data',
                      'application/x-www-form-urlencoded'):
        parser = FormDataParser()
        stream, form, files = parser.parse_from_environ(environ)
        value = ImmutableMultiDict(list(form.items()) + list(files.items()))
    else:
        raise exceptions.UnsupportedMediaType()

    return value
Esempio n. 3
0
def get_queryparams(environ: WSGIEnviron) -> http.QueryParams:
    return werkzeug.urls.url_decode(environ.get('QUERY_STRING', ''),
                                    cls=http.QueryParams)
Esempio n. 4
0
def get_querystring(environ: WSGIEnviron):
    return environ.get('QUERY_STRING', '')
Esempio n. 5
0
def get_port(environ: WSGIEnviron):
    if environ['wsgi.url_scheme'] == 'https':
        return int(environ.get('SERVER_PORT') or 443)
    return int(environ.get('SERVER_PORT') or 80)
Esempio n. 6
0
def get_host(environ: WSGIEnviron):
    return environ.get('HTTP_HOST') or environ['SERVER_NAME']
Esempio n. 7
0
def get_file_wrapper(environ: WSGIEnviron):
    return environ.get('wsgi.file_wrapper', FileWrapper)