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

Support write of read-only Buffer(s) for HTTP/2 #1171

Merged
merged 4 commits into from
Oct 10, 2020

Conversation

idelpivnitskiy
Copy link
Member

Motivation:

ServiceTalk provides a default BufferAllocator backed by netty's
ByteBufAllocator, but also provides a ReadOnlyBufferAllocator
implementation that does not depend on netty. AbstractH2DuplexHandler
currently supports only ServiceTalkBufferAllocator.

Modifications:

  • Share encodeAndRetain logic between HTTP/1.x and HTTP/2 encoders;
  • Add a test that verified both HTTP versions support all BufferAllocators;
  • Share HttpProtocol enum between different tests;
  • Implement ReadOnlyBufferAllocator.toString() for better output for test
    parameters;

Result:

HTTP/2 encoder supports Buffers produced by ReadOnlyBufferAllocator.

Motivation:

ServiceTalk provides a default `BufferAllocator` backed by netty's
`ByteBufAllocator`, but also provides a `ReadOnlyBufferAllocator`
implementation that does not depend on netty. `AbstractH2DuplexHandler`
currently supports only `ServiceTalkBufferAllocator`.

Modifications:
- Share `encodeAndRetain` logic between HTTP/1.x and HTTP/2 encoders;
- Add a test that verified both HTTP versions support all `BufferAllocator`s;
- Share `HttpProtocol` enum between different tests;
- Implement `ReadOnlyBufferAllocator.toString()` for better output for test
parameters;

Result:

HTTP/2 encoder supports `Buffer`s produced by `ReadOnlyBufferAllocator`.
StreamingHttpRequest request = streamingHttpConnection().post("/")
.payloadBody(from(allocator.fromAscii(payload)));
StreamingHttpResponse response = makeRequest(request);
assertResponse(response, protocol.version, OK, singletonList(payload));
Copy link
Member

Choose a reason for hiding this comment

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

not introduced by this PR but the validation of the getBodyAsListOfStrings doesn't seem right. The way data is written may not necessarily be the way data is read. fixed in #1173

@idelpivnitskiy idelpivnitskiy merged commit 597e8cd into apple:main Oct 10, 2020
@idelpivnitskiy idelpivnitskiy deleted the h2-ro-buffers branch October 10, 2020 02:02
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