aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/pytest-localserver/py3/pytest_localserver/http.py
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2025-02-02 10:11:17 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2025-02-02 10:21:23 +0300
commit637f8bbf610e99859dfbdbde49d99e9c60a7acf7 (patch)
tree3e685433e89f53a34ca2a4635c29865598d12b4f /contrib/python/pytest-localserver/py3/pytest_localserver/http.py
parentbbd3eacdd0520f608b6290efdd0050d7e55ad40d (diff)
downloadydb-637f8bbf610e99859dfbdbde49d99e9c60a7acf7.tar.gz
Intermediate changes
commit_hash:20c3eb2f2d78b5f654ec928c071692413a1bd96d
Diffstat (limited to 'contrib/python/pytest-localserver/py3/pytest_localserver/http.py')
-rw-r--r--contrib/python/pytest-localserver/py3/pytest_localserver/http.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/contrib/python/pytest-localserver/py3/pytest_localserver/http.py b/contrib/python/pytest-localserver/py3/pytest_localserver/http.py
index 0899597f5e..a4c3bef223 100644
--- a/contrib/python/pytest-localserver/py3/pytest_localserver/http.py
+++ b/contrib/python/pytest-localserver/py3/pytest_localserver/http.py
@@ -15,7 +15,6 @@ from werkzeug.wrappers import Response
class WSGIServer(threading.Thread):
-
"""
HTTP server running a WSGI application in its own thread.
"""
@@ -61,7 +60,6 @@ def _encode_chunk(chunk, charset):
class ContentServer(WSGIServer):
-
"""
Small test server which can be taught which content (i.e. string) to serve
with which response code. Try the following snippet for testing API calls::
@@ -89,12 +87,18 @@ class ContentServer(WSGIServer):
self.compress = None
self.requests = []
self.chunked = Chunked.NO
+ self.store_request_data = False
def __call__(self, environ, start_response):
"""
This is the WSGI application.
"""
request = Request(environ)
+
+ if self.store_request_data:
+ # need to invoke this method to cache the data
+ request.get_data(cache=True)
+
self.requests.append(request)
if (
request.content_type == "application/x-www-form-urlencoded"
@@ -129,7 +133,7 @@ class ContentServer(WSGIServer):
return response(environ, start_response)
- def serve_content(self, content, code=200, headers=None, chunked=Chunked.NO):
+ def serve_content(self, content, code=200, headers=None, chunked=Chunked.NO, store_request_data=True):
"""
Serves string content (with specified HTTP error code) as response to
all subsequent request.
@@ -138,6 +142,7 @@ class ContentServer(WSGIServer):
:param code: HTTP status code
:param headers: HTTP headers to be returned
:param chunked: whether to apply chunked transfer encoding to the content
+ :param store_request_data: whether to store data sent as request payload.
"""
if not isinstance(content, (str, bytes, list, tuple)):
# If content is an iterable which is not known to be a string,
@@ -153,6 +158,7 @@ class ContentServer(WSGIServer):
self.content = content
self.code = code
self.chunked = chunked
+ self.store_request_data = store_request_data
if headers:
self.headers = Headers(headers)