Support HEAD-only endpoint
wosc opened this issue · 1 comments
wosc commented
Just like there already are endpoints for get/post/put/patch/delete that only work vor those methods, it would be helpful to have httpbin.org/head that only accepts HEAD requests. Something like this, perhaps?
@app.route("/head", methods=("HEAD",))
def view_head():
"""The request's headers
---
tags:
- HTTP Methods
produces:
- application/json
responses:
200:
description: Echoes the request's headers as response headers (with an X-Echo- prefix).
"""
response = jsonify(get_dict("headers"))
for key, value in request.headers.items():
response.headers.add('X-Echo-%s' % key, value)
return response
The tricky part is probably how to include this new endpoint in the flasgger docs. While it's easy to enable HEAD generally, this picks it up for all endpoints that in principle allow HEAD, which are basically all that allow GET -- which creates way too much noise in the docs to be acceptable. With a quick look I could not find a way to "just include HEAD for this one endpoint", but I know basically nothing about flasgger, so I well might have missed something obvious.
-app.config["SWAGGER"] = {"title": "httpbin.org", "uiversion": 3}
+app.config["SWAGGER"] = {"title": "httpbin.org", "uiversion": 3,
+ "ignore_verbs": ('OPTIONS',)}
alphapapa commented
Agreed, this would be helpful.