Skip to content

Allow sending raw bytes in the response #35

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 1 commit into from
Jan 12, 2023
Merged

Conversation

deshipu
Copy link
Contributor

@deshipu deshipu commented Jan 11, 2023

We now only encode the body if it has an encode method, which usually means it's a string. This allows passing bytes, bytearray or memoryview.

I also changed the logic for sending a chunk, that avoids copying the data unnecessarily. I believe this also fixes a bug, where the size of unencoded chunk was sent, in characters, instead of encoded size, in bytes.

This fixes #33

We now only encode the body if it has an encode method, which usually
means it's a string. This allows passing bytes, bytearray or memoryview.

I also changed the logic for sending a chunk, that avoids copying the
data unnecessarily. I believe this also fixes a bug, where the size of
unencoded chunk was sent, in characters, instead of encoded size, in
bytes.
Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

Thanks for the fix and the non-copy improvement!

@dhalbert
Copy link
Contributor

@anecdata would you like to test, or shall I just merge?

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.

LGTM. Tested bytes and chunked bytes, with ASCII + emoji converted to bytes, varying chunk lengths. Thanks, @deshipu!

@dhalbert dhalbert merged commit 90c2801 into adafruit:main Jan 12, 2023
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jan 12, 2023
Updating https://github.com/adafruit/Adafruit_CircuitPython_IRRemote to 4.1.12 from 4.1.11:
  > trying 1.0.0 to make sure it'll get newer
  > Merge pull request adafruit/Adafruit_CircuitPython_IRRemote#59 from FoamyGuy/docs_theme_version
  > Merge pull request adafruit/Adafruit_CircuitPython_IRRemote#58 from FoamyGuy/docs_theme_version
  > Merge pull request adafruit/Adafruit_CircuitPython_IRRemote#57 from FoamyGuy/docs_theme_version
  > Merge pull request adafruit/Adafruit_CircuitPython_IRRemote#56 from FoamyGuy/docs_theme_version
  > Add .venv to .gitignore

Updating https://github.com/adafruit/Adafruit_CircuitPython_MAX1704x to 1.0.6 from 1.0.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_MAX1704x#10 from adafruit/retry-reset-esp32s3
  > Add .venv to .gitignore

Updating https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer to 2.1.0 from 2.0.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_HTTPServer#35 from deshipu/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation to 2.6.2 from 2.6.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_LED_Animation#107 from priestbh/main
  > Add .venv to .gitignore

Updating https://github.com/adafruit/Adafruit_CircuitPython_Ticks to 1.0.9 from 1.0.8:
  > Merge pull request adafruit/Adafruit_CircuitPython_Ticks#9 from xgpt/patch-1
  > Add .venv to .gitignore
  > Update .pylintrc for v2.15.5
  > Fix release CI files
  > Update pylint to 2.15.5
  > Updated pylint version to 2.13.0
  > Switching to composite actions

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.

Allow Response to send bytes
3 participants