Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Endpoint Description
`/forms/post`_ HTML form that submits to */post*
`/xml`_ Returns some XML
`/encoding/utf8`_ Returns page containing UTF-8 data.
`/version`_ Returns the used HTTP version
====================================== ==================================================================================================================

.. _/user-agent: http://httpbin.org/user-agent
Expand Down Expand Up @@ -94,6 +95,7 @@ Endpoint Description
.. _/forms/post: http://httpbin.org/forms/post
.. _/xml: http://httpbin.org/xml
.. _/encoding/utf8: http://httpbin.org/encoding/utf8
.. _/version: http://httpbin.org/version


DESCRIPTION
Expand Down
6 changes: 6 additions & 0 deletions httpbin/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,12 @@ def xml():
response.headers["Content-Type"] = "application/xml"
return response

@app.route('/version')
def view_http_version():
"""Returns HTTP Version."""

return jsonify({'version': request.environ.get('SERVER_PROTOCOL')})


if __name__ == '__main__':
parser = argparse.ArgumentParser()
Expand Down
10 changes: 10 additions & 0 deletions test_httpbin.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,16 @@ def test_tracking_enabled(self):
self.assertIn('google-analytics', data)
self.assertIn('perfectaudience', data)

def test_http_version(self):
response = self.app.get(
'/version',
environ_overrides={
'SERVER_PROTOCOL': 'HTTP/3.1',
}
)

data = response.data.decode('utf-8')
self.assertIn('"version": "HTTP/3.1"', data)

if __name__ == '__main__':
unittest.main()