Skip to content
Merged
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
4 changes: 2 additions & 2 deletions pytest_httpserver/httpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def expect_request(
:param uri: URI of the request. This must be an absolute path starting with ``/``, a
:py:class:`URIPattern` object, or a regular expression compiled by :py:func:`re.compile`.
:param method: HTTP method of the request. If not specified (or `METHOD_ALL`
specified), all HTTP requests will match.
specified), all HTTP requests will match. Case insensitive.
:param data: payload of the HTTP request. This could be a string (utf-8 encoded
by default, see `data_encoding`) or a bytes object.
:param data_encoding: the encoding used for data parameter if data is a string.
Expand All @@ -653,7 +653,7 @@ def expect_request(

matcher = self.create_matcher(
uri,
method=method,
method=method.upper(),
data=data,
data_encoding=data_encoding,
headers=headers,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
features:
- |
HTTP methods are case insensitive. The HTTP method specified is converted to
uppercase in the library.
8 changes: 8 additions & 0 deletions tests/test_permanent.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ def test_request_post(httpserver: HTTPServer):
assert response.status_code == 200


def test_request_post_case_insensitive_method(httpserver: HTTPServer):
httpserver.expect_request("/foobar", data='{"request": "example"}', method="post").respond_with_data("example_response")
response = requests.post(httpserver.url_for("/foobar"), json={"request": "example"})
httpserver.check_assertions()
assert response.text == "example_response"
assert response.status_code == 200


def test_request_any_method(httpserver: HTTPServer):
httpserver.expect_request("/foobar").respond_with_data("OK")
response = requests.post(httpserver.url_for("/foobar"))
Expand Down