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 support for httpx.Response(content=..., text=..., html=..., json=...) #1250

Closed
wants to merge 9 commits into from

Conversation

tomchristie
Copy link
Member

Closes #1227

Adds support for eg...

  • httpx.Response(200, content=b'Hello, world')
  • httpx.Response(200, text='Hello, world')
  • httpx.Response(200, html='Hello, world')
  • httpx.Response(200, json={'Hello': 'world'})

Plus streaming cases...

  • httpx.Response(200, content=<byte iterator>)
  • httpx.Response(200, content=<byte aiterator>)

There are some test cases we'd be able to smarten up after this, but I'll leave that for a follow up.

@@ -95,21 +92,14 @@ def __iter__(self) -> typing.Iterator[bytes]:
def __aiter__(self) -> typing.AsyncIterator[bytes]:
raise RuntimeError("Attempted to call a async iterator on an sync stream.")

def close(self) -> None:
if self.close_func is not None:
self.close_func()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out we don't really need close_func on IteratorStream/AsyncIteratorStream anymore, which falls out from updating test cases to use Response(content=<bytes iterator>)

raise httpcore.NetworkError(exc) from exc

def close(self) -> None:
self._conn.release_conn()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in this module are redundant given #1182, but I've updated this all the same since this PR removes close_func from our internal IteratorStream.

@tomchristie tomchristie added the enhancement New feature or request label Sep 2, 2020
@j178 j178 force-pushed the content-parameters-on-response branch from 0744e4d to 266bfa1 Compare September 3, 2020 01:46
@tomchristie tomchristie changed the title Add support for `httpx.Response(content=..., text=..., html=..., json=...) Add support for httpx.Response(content=..., text=..., html=..., json=...) Sep 3, 2020
@tomchristie
Copy link
Member Author

If we need to narrow down the scope of this for review purposes, I'd be happy to think about how best to do that.

@tomchristie tomchristie marked this pull request as draft September 7, 2020 08:51
@tomchristie
Copy link
Member Author

Putting this in draft to instead tackle the intent here in a more targeted manner.
See #1265 for a more slimmed-down approach.

@tomchristie tomchristie mentioned this pull request Sep 17, 2020
@tomchristie
Copy link
Member Author

Closing in favour of #1297

@tomchristie tomchristie deleted the content-parameters-on-response branch September 18, 2020 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Supporting Response(content=..., text=..., html=..., json=...)
2 participants