Skip to content

Commit db72302

Browse files
committed
httpserver.py: make http method case-insensitive
When creating a matcher, it should not matter whether the method is specified as 'get' or 'GET'. At the end it will be converted to uppercase. Fixes #40.
1 parent 8eb0d32 commit db72302

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

pytest_httpserver/httpserver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ def expect_request(
634634
:param uri: URI of the request. This must be an absolute path starting with ``/``, a
635635
:py:class:`URIPattern` object, or a regular expression compiled by :py:func:`re.compile`.
636636
:param method: HTTP method of the request. If not specified (or `METHOD_ALL`
637-
specified), all HTTP requests will match.
637+
specified), all HTTP requests will match. Case insensitive.
638638
:param data: payload of the HTTP request. This could be a string (utf-8 encoded
639639
by default, see `data_encoding`) or a bytes object.
640640
:param data_encoding: the encoding used for data parameter if data is a string.
@@ -653,7 +653,7 @@ def expect_request(
653653

654654
matcher = self.create_matcher(
655655
uri,
656-
method=method,
656+
method=method.upper(),
657657
data=data,
658658
data_encoding=data_encoding,
659659
headers=headers,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
HTTP methods are case insensitive. The HTTP method specified is converted to
5+
uppercase in the library.

tests/test_permanent.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ def test_request_post(httpserver: HTTPServer):
4141
assert response.status_code == 200
4242

4343

44+
def test_request_post_case_insensitive_method(httpserver: HTTPServer):
45+
httpserver.expect_request("/foobar", data='{"request": "example"}', method="post").respond_with_data("example_response")
46+
response = requests.post(httpserver.url_for("/foobar"), json={"request": "example"})
47+
httpserver.check_assertions()
48+
assert response.text == "example_response"
49+
assert response.status_code == 200
50+
51+
4452
def test_request_any_method(httpserver: HTTPServer):
4553
httpserver.expect_request("/foobar").respond_with_data("OK")
4654
response = requests.post(httpserver.url_for("/foobar"))

0 commit comments

Comments
 (0)