Skip to content

Case insensitive HTTPHeaders, HTTPResponse context manager and some fixes #29

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

Merged
merged 22 commits into from
Jan 2, 2023
Merged

Case insensitive HTTPHeaders, HTTPResponse context manager and some fixes #29

merged 22 commits into from
Jan 2, 2023

Conversation

michalpokusa
Copy link
Contributor

@michalpokusa michalpokusa commented Dec 19, 2022

Added separate class for HTTP headers, that allows accessing headers using case-insensitive names.

Also, changed some docstrings the were unclear and one that was misleading as it was inconsistent with the code.

Changed the order of Docs References, so that the most "important" ones are on the top, with enums and dataclass-like classes below.

Updated library version to 1.1.0 in sphinx configuration file.

Fixes #26
Fixes #28

@michalpokusa michalpokusa marked this pull request as ready for review December 19, 2022 21:39
@anecdata
Copy link
Member

anecdata commented Dec 22, 2022

@michalpokusa Any thoughts on this 404 issue? #28 (comment) I don't see anything obvious in this PR that would have affected it. Maybe it came in with the refactor and just wasn't noticed until now. Worth a separate issue?

@michalpokusa
Copy link
Contributor Author

@michalpokusa Any thoughts on this 404 issue? #28 (comment) I don't see anything obvious in this PR that would have affected it. Maybe it came in with the refactor and just wasn't noticed until now. Worth a separate issue?

Working on it, also I see that other PR was merged and there are merge conflicts, so I will fix both before proceeding

@michalpokusa michalpokusa marked this pull request as draft December 22, 2022 18:42
@michalpokusa michalpokusa changed the title Case insensitive HTTPHeaders and some fixes Case insensitive HTTPHeaders, HTTPResponse context manager and some fixes Dec 23, 2022
@michalpokusa
Copy link
Contributor Author

michalpokusa commented Dec 23, 2022

After merging recently updated main branch i noticed some inconsistencies wit hthe HTTPResponse API, mainy the fact that some function would accept conn and some not. Also in chunked response sending headers and empty chunk to finish transfer should be implicit.

I decided to modify the HTTPResposne API to be unified by using context managers, by doings so i was able to reduce abstraction and number of lines of actual code, the PR may not show this as I added/extended some docstrings.

Also fixed the 404 problem in #28.

Using context managers all of the examples below are allowed.
image

@paul-1
Copy link
Contributor

paul-1 commented Dec 23, 2022

That for sure looks a lot cleaner. Thanks for doing that

@michalpokusa michalpokusa marked this pull request as ready for review December 23, 2022 18:58
@michalpokusa michalpokusa marked this pull request as draft December 24, 2022 06:29
@michalpokusa
Copy link
Contributor Author

In the meantime I updated examples to new "context manager way" of serving response. Did some testing on my own and I believe that it works as it should. Also I added raising error if someone tries to use .send() or .send_file() multiple times per response.

@michalpokusa michalpokusa marked this pull request as ready for review December 26, 2022 13:25
Copy link
Contributor

@paul-1 paul-1 left a comment

Choose a reason for hiding this comment

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

I tested my use cases, and everything seemed to work fine, with exception of sending html in chunked mode.

@michalpokusa
Copy link
Contributor Author

@anecdata Could be please take a look at the current state of this PR. I believe there is everything I wanted to add and that it is ready to be merged.

In the c758e51 commit I also "included" the #30.

Copy link
Member

@anecdata anecdata left a comment

Choose a reason for hiding this comment

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

Tested file serving, GET, POST, a couple of MIME types, custom HTTP status code, chunked and non-chunked response bodies, multi-byte characters in response, accessing the client address.

This is a pretty large change in API, so we should change the version number accordingly.

This looks good to me, one minor thing.

Copy link
Member

@anecdata anecdata left a comment

Choose a reason for hiding this comment

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

Thanks, @michalpokusa. And thanks @bill88t for #30 included here.

@dhalbert
Copy link
Contributor

dhalbert commented Jan 2, 2023

This should be 2.0.0 if there are incompatible API or use changes. A major version change means a code rewrite is needed.

@michalpokusa
Copy link
Contributor Author

michalpokusa commented Jan 2, 2023

This should be 2.0.0 if there are incompatible API or use changes. A major version change means a code rewrite is needed.

If I understand correctly, the code stays the same, only tag changes, so no further edits are needed on my part to make it 2.0.0

@bill88t
Copy link

bill88t commented Jan 2, 2023

Closing #30 then. Thanks for taking care of it!

@dhalbert
Copy link
Contributor

dhalbert commented Jan 2, 2023

If I understand correctly, the code stays the same, only tag changes, so no further edits are needed on my part to make it 2.0.0

Right, when I or whoever makes a release, it will be 2.0.0. There are incompatible API or use changes, right?

@michalpokusa
Copy link
Contributor Author

There are incompatible API or use changes, right?

Yes, instead of returning HTTPResponse instance in route handlers, the function should call a method on HTTPResponse, so all handlers need to be slightly modified, but still.

@dhalbert
Copy link
Contributor

dhalbert commented Jan 2, 2023

Great - I will make a release now.

I only found one use of this library in the Learn guides:
https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/PicoW_CircuitPython_HTTP_Server/code.py
Could someone take a look at that and see if there are any changes to be made? Thanks.

@dhalbert dhalbert merged commit e4a7e0e into adafruit:main Jan 2, 2023
@michalpokusa
Copy link
Contributor Author

michalpokusa commented Jan 2, 2023

Great - I will make a release now.

I only found one use of this library in the Learn guides: https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/PicoW_CircuitPython_HTTP_Server/code.py Could someone take a look at that and see if there are any changes to be made? Thanks.

Thanks for merging.

Yes, there will be a small change in base and buttonpress functions. I could make the required changes, but I will be unable to test it on intended hardware as I do not own a Raspberry Pico W.

@anecdata
Copy link
Member

anecdata commented Jan 2, 2023

Maybe if Liz still has it set up, it would be easy for her to test. I have a Pico W and could test the routes, but I don't have the peripherals, so I'd stub out the I/O (possibly introducing or masking an issue).

Any network code written for raspberrypi should run on espressif (but not necessarily vice versa since there are some things not implemented / not implementable).

@dhalbert
Copy link
Contributor

dhalbert commented Jan 3, 2023

If you either of you could make a draft PR, I'll test it by simplifying or setting up the base hardware. Thanks.

@anecdata
Copy link
Member

anecdata commented Jan 3, 2023

adafruit/Adafruit_Learning_System_Guides#2375

adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants