psaegert's picture
Upload 201 files
2c34d2f
if "wsgi.input_terminated" in request.environ:
app.logger.debug(
"environ wsgi.input_terminated already set, keeping: %s"
% request.environ["wsgi.input_terminated"]
)
else:
request.environ["wsgi.input_terminated"] = 1
else:
abort(501, "Chunked requests are not supported for server %s" % server)
@app.after_request
def set_cors_headers(response):
response.headers["Access-Control-Allow-Origin"] = request.headers.get("Origin", "*")
response.headers["Access-Control-Allow-Credentials"] = "true"
if request.method == "OPTIONS":
# Both of these headers are only used for the "preflight request"
# http://www.w3.org/TR/cors/#access-control-allow-methods-response-header
response.headers[
"Access-Control-Allow-Methods"
] = "GET, POST, PUT, DELETE, PATCH, OPTIONS"
response.headers["Access-Control-Max-Age"] = "3600" # 1 hour cache
if request.headers.get("Access-Control-Request-Headers") is not None:
response.headers["Access-Control-Allow-Headers"] = request.headers[
"Access-Control-Request-Headers"
]
return response
# ------
# Routes
# ------
@app.route("/legacy")
def view_landing_page():
"""Generates Landing Page in legacy layout."""
return render_template("index.html")
@app.route("/html")
def view_html_page():
"""Returns a simple HTML document.
---
tags:
- Response formats
produces:
- text/html
responses:
200:
description: An HTML page.
"""
return render_template("moby.html")
@app.route("/robots.txt")
def view_robots_page():
"""Returns some robots.txt rules.
---
tags:
- Response formats
produces:
- text/plain
responses:
200:
description: Robots file
"""
response = make_response()
response.data = ROBOT_TXT
response.content_type = "text/plain"
return response
@app.route("/deny")
def view_deny_page():
"""Returns page denied by robots.txt rules.
---
tags:
- Response formats
produces:
- text/plain
responses:
200:
description: Denied message
"""
response = make_response()
response.data = ANGRY_ASCII
response.content_type = "text/plain"
return response
# return "YOU SHOULDN'T BE HERE"
@app.route("/ip")
def view_origin():
"""Returns the requester's IP Address.
---
tags:
- Request inspection
produces:
- application/json
responses:
200:
description: The Requester's IP Address.
"""
return jsonify(origin=request.headers.get("X-Forwarded-For", request.remote_addr))
@app.route("/uuid")
def view_uuid():
"""Return a UUID4.
---
tags:
- Dynamic data
produces:
- application/json
responses:
200:
description: A UUID4.
"""
return jsonify(uuid=str(uuid.uuid4()))
@app.route("/headers")
def view_headers():
"""Return the incoming request's HTTP headers.
---
tags:
- Request inspection
produces:
- application/json
responses:
200:
description: The request's headers.
"""
return jsonify(get_dict('headers'))
@app.route("/user-agent")
def view_user_agent():
"""Return the incoming requests's User-Agent header.
---
tags:
- Request inspection
produces:
- application/json
responses:
200:
description: The request's User-Agent header.
"""
headers = get_headers()
return jsonify({"user-agent": headers["user-agent"]})
@app.route("/get", methods=("GET",))
def view_get():
"""The request's query parameters.
---
tags:
- HTTP Methods
produces:
- application/json
responses:
200:
description: The request's query parameters.
"""
return jsonify(get_dict("url", "args", "headers", "origin"))
@app.route("/anything", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "TRAC