Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add iter_lines Method to FastHttpSession Class #3023

Closed
wants to merge 2 commits into from
Closed
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
12 changes: 12 additions & 0 deletions locust/contrib/fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,18 @@ def get(self, url: str, **kwargs: Unpack[RESTKwargs]) -> ResponseContextManager
"""Sends a GET request"""
return self.request("GET", url, **kwargs)

def iter_lines(self, url: str, **kwargs) -> Generator[str, None, None]:
"""Sends a iter_lines request"""
response = self.request("GET", url, stream=True, **kwargs)
response.raise_for_status() # Check for HTTP errors

buffer = ''
for chunk in response.iter_content(chunk_size=1024):
buffer += chunk.decode('utf-8')
while '\n' in buffer:
line, buffer = buffer.split('\n', 1)
yield line

def head(self, url: str, **kwargs: Unpack[RESTKwargs]) -> ResponseContextManager | FastResponse:
"""Sends a HEAD request"""
return self.request("HEAD", url, **kwargs)
Expand Down
Loading