diff --git a/README.rst b/README.rst index 69231c5e..fc7cdebf 100644 --- a/README.rst +++ b/README.rst @@ -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 @@ -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 diff --git a/httpbin/core.py b/httpbin/core.py index e3ca094f..978c342e 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -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() diff --git a/test_httpbin.py b/test_httpbin.py index 4f6a3227..205debf8 100755 --- a/test_httpbin.py +++ b/test_httpbin.py @@ -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()