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

Server headers, FormData, some docs improvements and fix for bug in ChunkedResponse #58

Merged
merged 17 commits into from
Jul 17, 2023

Conversation

michalpokusa
Copy link
Contributor

@michalpokusa michalpokusa commented Jun 9, 2023

PR does not contain any breaking changes, I suggest publishing it as 4.1.0.

⭐ Added:

  • FormData class and Request.form_data for parsing POST body for "application/x-www-form-urlencoded", "multipart/form-data", "text/plain" content types.
  • Example that shows new functionality.
  • Server.headers for setting headers that are sent with every response, without need for explicitly adding them in constructor.
  • EDIT1: Server.poll() return value that indicates the result of polling e.g. NO_REQUEST or REQUEST_HANDLED_RESPONSE_SENT.

🛠️ Updated:

  • Multiple docstrings are more verbose.
  • Fix: In ChunkedResponse sending empty chunk was breaking functionality, because it ended response prematurely.
  • Updated docs.
  • EDIT1: Server.stopped is set to True in constructor, it changes to False only after calling .start() .server_forever().

🏗️ Refactor:

  • Unified query_params and form_data to use _IFieldStorage for shared functionality.

@michalpokusa michalpokusa changed the title Server headers, some docs improvements and fix for bug in ChunkedResponse Server headers, FormData, some docs improvements and fix for bug in ChunkedResponse Jun 11, 2023
@michalpokusa
Copy link
Contributor Author

If possible, please test the impact of these changes to request processing speed. In theory there should not be much overhead, but in my testing I noticed a very big range (80ms-500ms). Although this might be caused by my WiFi and the connection itself, it we be great it anyone could eliminate the possibility that it is the code's fault.

Thanks in advance. 🙂

@michalpokusa michalpokusa marked this pull request as ready for review June 30, 2023 11:25
enctype = request.query_params.get("enctype", "text/plain")

if request.method == POST:
posted_value = request.data.get("something")
Copy link
Contributor

Choose a reason for hiding this comment

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

I got an exception here for request not having property data I think maybe this is supposed to be form_data instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, this should be form_data. Already fixed.

@michalpokusa michalpokusa marked this pull request as draft July 1, 2023 15:11
@michalpokusa michalpokusa marked this pull request as ready for review July 6, 2023 20:05
Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

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

These changes look good to me.

I've retested all modified examples on a Feather S3 TFT with the latest versions.

Really great new functionality and improved docstrings. Thanks @michalpokusa!

@FoamyGuy FoamyGuy merged commit e989afe into adafruit:main Jul 17, 2023
1 check passed
@michalpokusa michalpokusa deleted the server-headers branch July 17, 2023 17:17
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jul 18, 2023
Updating https://github.com/adafruit/Adafruit_CircuitPython_FocalTouch to 1.4.9 from 1.4.8:
  > Merge pull request adafruit/Adafruit_CircuitPython_FocalTouch#26 from adafruit/ladyada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_MAX9744 to 1.2.15 from 1.2.14:
  > Merge pull request adafruit/Adafruit_CircuitPython_MAX9744#17 from kbsriram/add-typing

Updating https://github.com/adafruit/Adafruit_CircuitPython_Nunchuk to 1.1.9 from 1.1.8:
  > Merge pull request adafruit/Adafruit_CircuitPython_Nunchuk#31 from adafruit/stemma_i2c

Updating https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display to 3.12.0 from 3.11.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_RGB_Display#114 from makermelissa/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_Seesaw to 1.14.0 from 1.13.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_seesaw#118 from ladyada/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_asyncio to 0.5.23 from 0.5.22:
  > Merge pull request adafruit/Adafruit_CircuitPython_asyncio#44 from furbrain/main
  > Merge pull request adafruit/Adafruit_CircuitPython_asyncio#42 from tekktrik/dev/fix-build-bundle

Updating https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer to 4.1.0 from 4.0.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_HTTPServer#59 from FoamyGuy/ethernet_example
  > Merge pull request adafruit/Adafruit_CircuitPython_HTTPServer#58 from michalpokusa/server-headers

Updating https://github.com/adafruit/Adafruit_CircuitPython_NTP to 3.0.10 from 3.0.9:
  > Merge pull request adafruit/Adafruit_CircuitPython_NTP#30 from joshua-beck-0908/timezone_fix

Updating https://github.com/adafruit/Adafruit_CircuitPython_PortalBase to 1.14.9 from 1.14.8:
  > Merge pull request adafruit/Adafruit_CircuitPython_PortalBase#92 from makermelissa/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Updated download stats for the libraries
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