Skip to content

Conversation

SpotlightKid
Copy link
Contributor

  • Add response_class keyword arg to urequests.request,
    which defaults to urequests.Response and is used to
    instantiate the object handling the HTTP response.
  • Call set_header method on instance of given response
    class for every received header line, which takes an
    unparsed header line as a byte string.
  • Add no-op set_header method to urequests.Response.

This could be used to store the response headers in a custom response class as demonstrated in this comment for #217. It is the responsibility of the custom response class to properly parse and assemble headers (e.g. ones with continuation lines).

* Add `response_class` keyword arg to `urequests.request`,
  which defaults to `urequests.Response` and is used to
  instantiate the object handling the HTTP response.
* Call `set_header` method (if defined) on instance of given
  response class for every received header line, which takes
  an unparsed header line as a byte string.
@SpotlightKid SpotlightKid force-pushed the feature/urequests-custom-response branch from 341530c to a0abe1e Compare August 7, 2018 23:16
@SpotlightKid
Copy link
Contributor Author

SpotlightKid commented Aug 7, 2018

Simplified the patch by checking for the set_header method on the response object first (only once), which makes the dummy method on urequests.Response superfluous.

@andrewleech
Copy link
Contributor

Thanks to the dynamic nature of (micro)python the class replacement can already be done with normal monkey-patching, eg.

import urequests

class Response(urequests.Response)
    def set_header(self, line):
        pass # do stuff

urequests.Response = Response

The other change here to extend headers handling I think would be covered by 5854ae1 recently merged as part of #500.

Feel free to re-open / update the PR if I've missed something.

@andrewleech andrewleech closed this Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants