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

extend Body with reader/writer semantics, split Chunked_body #972

Closed
wants to merge 3 commits into from

Conversation

bikallem
Copy link
Contributor

This PR is split off from #969 and builds on top of #971. Therefore only the last 2 commits belong to this PR. The first commit should go away with rebase to master after #971 is merged.

The PR improves the abstraction mechanism to define/use HTTP request/response body. A HTTP request/response body needs to also define Headers that go along with it. For e.g. a fixed body needs at least a Content-Type and Content-Length header, a chunked encoding needs Transfer-Encoding headers and possibly a Trailer header and trailers, A JSON body needs a different Content-Type value and so on. The current abstraction is leaky since it leaves an important requirement for the user of the library to devise/figure out and makes reuse of writers a bit less useful and convenient.

The current Body.t type also lacks a precise/formal notion of reading a body, for e.g. we have Custom buf_write for writing a body but we lack similar mechanism for reading. From the types (in the Body) it we get a sense that they are mostly for writing the body and not for reading the body.

The reader/writer abstraction aims to address the shortcomings identified above. We no longer need the brittle Body.t. However, for the purposes of keeping the trunk/master buildable, tests passing and the CI green, we still retain the "legacy" code in this PR. Body.t will be cleaned up in a future PR after Server/Client PRs (future PRs) are merged.

Body.writer abstracts HTTP request/response body that can be written. Body.reader abstracts HTTP request/response body that can be read. The PR includes implementations of two common writers/readers, content_writer/reader and form_values_writer/reader in Body module.

content_writer/reader encapsulates previous Fixed body semantics and form_values_writer/reader is a new body that reuses content_writer/reader to implement HTTP form body writing/reading. Notice the convenience with which we reuse writers/readers. Future PRs should add json and xml reader/writer by again reusing the content_writer/reader.

Chunked encoding is split into separate module Chunked_body and now follows the reader/writer semantics. However, as mentioned above the Body module still includes chunked body functionality for now so as to keep the ci/trunk green. This duplication will be cleaned up once the relevant future PRs are merged.

/cc @patricoferris @mseri

Rwer module mostly served as miscellaneous dump bag of various
readers and writers. The name Rwer always felt a bit incoherent even
when it was initially added. However, I couldn't quite pin the correct
module name for it. Recently, while working on another PR, it dawned
on me that the readers and writers can be logically split into
Buf_read and Buf_write modules by extending Eio Buf_read and Buf_write
modules respectively.
Extend Body module with writer/reader semantics.
Splits Chunked_body module from Body module. Add reader/writer for
HTTP chunked encoding.
@bikallem
Copy link
Contributor Author

Closing this in support of discussion happening at #969

@bikallem bikallem closed this Feb 23, 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
Development

Successfully merging this pull request may close these issues.

1 participant