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

Ensure Content-Length is set for Responses that need it #74

Merged
merged 8 commits into from
Feb 18, 2024

Conversation

mfelsche
Copy link
Contributor

@mfelsche mfelsche commented Feb 10, 2024

For all ways to construct responses, ensure that they have a Content-Length header, adding one with 0 as value if none was provided.
Do not add one for responses with Transfer-Encoding: chunked.

This adds some overhead to building responses, but ensures (in a reasonable way) for legit API uses, that valid responses fall out in the end. Performance impact hasn't been measured yet, but can be done if desired.

This also included various internal fixes and some streamlining of response APIs. Overall I would consider this a non-backwards-compatible release.

Obsoletes #71

@mfelsche mfelsche requested a review from SeanTAllen February 10, 2024 23:14
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Feb 10, 2024
@SeanTAllen SeanTAllen added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Feb 10, 2024
@ponylang-main
Copy link
Contributor

Hi @mfelsche,

The changelog - fixed label was added to this pull request; all PRs with a changelog label need to have release notes included as part of the PR. If you haven't added release notes already, please do.

Release notes are added by creating a uniquely named file in the .release-notes directory. We suggest you call the file 74.md to match the number of this pull request.

The basic format of the release notes (using markdown) should be:

## Title

End user description of changes, why it's important,
problems it solves etc.

If a breaking change, make sure to include 1 or more
examples what code would look like prior to this change
and how to update it to work after this change.

Thanks.

@SeanTAllen SeanTAllen added the changelog - changed Automatically add "Changed" CHANGELOG entry on merge label Feb 10, 2024
@SeanTAllen
Copy link
Member

@mfelsche I think this should get 2 changelog entries. And two release notes. As this is pretty much two changes.

  1. the fix for including content-length for one shot.
  2. the stuff that is "a breaking change"

can you manually add the slightly different and appropriate CHANGELOG entries. 1 to changed and 1 to fixed?

and manually add to next-release.md. different entries with names that match those in the changelog. the fixed should be simple, for the changed, detail what has changed about the API and what needs to be updated to adjust?

also you need to rebase it appears.

Copy link
Member

@SeanTAllen SeanTAllen left a comment

Choose a reason for hiding this comment

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

I left a comment with "changes". Basically, the changelog entries and release notes entries.

mw and others added 4 commits February 11, 2024 21:59
except cor chunked encoding
especially change set_transfer_coding to set_transfer_encoding
and allow ByteSeq instead of only Array[U8] val

and add some more tests for the ResponseBuilder
@mfelsche mfelsche force-pushed the content-length-response branch from afcbc01 to f166243 Compare February 11, 2024 21:02
CHANGELOG.md Outdated
@@ -6,12 +6,24 @@ All notable changes to this project will be documented in this file. This projec

### Fixed

- Responses without `Transfer-Encoding: chunked` had no `Content-Length` header set when not done explicitly. This made some clients (e.g. curl) hang.
Copy link
Member

Choose a reason for hiding this comment

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

This isn't a changelog entry. It's very long. This should be a short title and link to the PR

Same for all the others.

Copy link
Member

Choose a reason for hiding this comment

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

our standard is along the lines of this one I pulled as an example from the file:

- Update to ponylang/net_ssl 1.3.2 ([PR #69](https://github.com/ponylang/http_server/pull/69))

Comment on lines 6 to 15
## Response Creation API changes and Additions

- `Response.transfer_coding()` changed to `Response.transfer_encoding()`.

- `ResponseBuilderHeaders.set_content_length(content_length: USize)` has been added to set a content-length from a numeric value.
- `ResponseBuilderBody.add_chunk()` now takes a `ByteSeq` instead of `Array[U8] val`. This allows for passing `String val` as well.

- `BuildableResponse.create()` now only takes a `Status` and a `Version`. Content-Length and Transfer-Encoding can be set later with `set_content_length()` and `set_transfer_encoding()`
- `BuildableResponse.delete_header(header_name: String)` was added to enable deletion of headers that have been set previously.
- `BuildableResponse.set_transfer_coding()` changed to `BuildableResponse.set_transfer_encoding()`
Copy link
Member

Choose a reason for hiding this comment

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

Can you make these individual entries as appropriate with "before and after" code examples?

The name for each ## entry should match up with an entry in the CHANGELOG.

@SeanTAllen SeanTAllen removed changelog - changed Automatically add "Changed" CHANGELOG entry on merge changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge labels Feb 18, 2024
@SeanTAllen SeanTAllen merged commit 8083d43 into main Feb 18, 2024
5 checks passed
@SeanTAllen SeanTAllen deleted the content-length-response branch February 18, 2024 19:07
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Feb 18, 2024
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.

3 participants