Created
November 24, 2020 09:19
-
-
Save CTimmerman/33c2b168eaeab693e79d79f2ae010ad9 to your computer and use it in GitHub Desktop.
Simple debugging HTTP server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding: utf8 | |
""" Simple debugging HTTP server | |
2020-11-20 v1.0 by Cees Timmerman | |
""" | |
import logging | |
from pprint import pformat as pf | |
from flask import Flask, request, make_response | |
app = Flask(__name__) | |
log = logging.getLogger('werkzeug') | |
@app.route('/', defaults={'path': ''}) | |
@app.route('/<path:path>', methods=["GET", "POST", "OPTIONS"]) | |
def read(path): | |
"""request['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_cached_json', '_get_data_for_json', '_get_file_stream', '_get_stream_for_parsing', '_load_form_data', '_parse_content_type', 'accept_charsets', 'accept_encodings', 'accept_languages', 'accept_mimetypes', 'access_control_request_headers', 'access_control_request_method', 'access_route', 'application', 'args', 'authorization', 'base_url', 'blueprint', 'cache_control', 'charset', 'close', 'content_encoding', 'content_length', 'content_md5', 'content_type', 'cookies', 'data', 'date', 'dict_storage_class', 'disable_data_descriptor', 'encoding_errors', 'endpoint', 'environ', 'files', 'form', 'form_data_parser_class', 'from_values', 'full_path', 'get_data', 'get_json', 'headers', 'host', 'host_url', 'if_match', 'if_modified_since', 'if_none_match', 'if_range', 'if_unmodified_since', 'input_stream', 'is_json', 'is_multiprocess', 'is_multithread', 'is_run_once', 'is_secure', 'json', 'json_module', 'list_storage_class', 'make_form_data_parser', 'max_content_length', 'max_form_memory_size', 'max_forwards', 'method', 'mimetype', 'mimetype_params', 'on_json_loading_failed', 'origin', 'parameter_storage_class', 'path', 'pragma', 'query_string', 'range', 'referrer', 'remote_addr', 'remote_user', 'routing_exception', 'scheme', 'script_root', 'shallow', 'stream', 'trusted_hosts', 'url', 'url_charset', 'url_root', 'url_rule', 'user_agent', 'values', 'view_args', 'want_form_data_parsed']""" | |
res = f"{request.method} /{path} {pf(list(request.form.items()))} {pf({k:getattr(request, k) for k in dir(request) if k in ['args', 'data', 'form', 'headers', 'json', 'referrer', 'remote_addr', 'remote_user', 'values']})}" | |
log.error(res) | |
resp = make_response({}) | |
resp.headers['Access-Control-Allow-Headers'] = '*' | |
resp.headers['Access-Control-Allow-Origin'] = '*' | |
log.error(pf(resp.headers)) | |
return resp | |
if __name__ == '__main__': | |
app.run(debug=True) # http://127.0.0.1:5000/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment