use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class AbsoluteAddressHttpRequesterFilterTest method shouldNotAddAuthorityToAbsoluteFormRequestTarget.
@Test
void shouldNotAddAuthorityToAbsoluteFormRequestTarget() throws Exception {
request.requestTarget("https://otherhost:443/otherpath?otherQuery");
filter.request(request).toFuture().get();
verify(delegate).request(requestCapture.capture());
final StreamingHttpRequest capturedRequest = requestCapture.getValue();
MatcherAssert.assertThat(capturedRequest.requestTarget(), is("https://otherhost:443/otherpath?otherQuery"));
}
use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class AbstractConditionalHttpFilterTest method testFilter.
private void testFilter(boolean expectAccepted) throws Exception {
final StreamingHttpRequest req = REQ_RES_FACTORY.get(expectAccepted ? "/accept" : "/reject");
final StreamingHttpResponse res = sendTestRequest(req).toFuture().get();
assertThat(res.headers().get(FILTERED_HEADER), is(Boolean.toString(expectAccepted)));
}
use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class AbstractEchoServerBasedHttpRequesterTest method makeRequestValidateResponseAndClose.
static void makeRequestValidateResponseAndClose(StreamingHttpRequester requester) throws ExecutionException, InterruptedException {
try {
StreamingHttpRequest request = requester.get("/request?foo=bar&foo=baz").payloadBody(from(DEFAULT_ALLOCATOR.fromAscii("Testing123")));
request.headers().set(HOST, "mock.servicetalk.io");
StreamingHttpResponse resp = awaitIndefinitelyNonNull(requester.request(request).retryWhen(retryWithExponentialBackoffFullJitter(10, t -> true, ofMillis(100), ofDays(10), CTX.executor())));
assertThat(resp.status(), equalTo(OK));
Single<String> respBody = resp.payloadBody().collect(StringBuilder::new, (sb, buf) -> {
sb.append(buf.toString(UTF_8));
return sb;
}).map(StringBuilder::toString);
HttpHeaders headers = resp.headers();
assertThat(headers.get("test-req-method"), hasToString(GET.toString()));
assertThat(headers.get("test-req-target"), hasToString("/request?foo=bar&foo=baz"));
assertThat(headers.get("test-req-header-host"), hasToString("mock.servicetalk.io"));
assertThat(headers.get("test-req-header-transfer-encoding"), equalTo(CHUNKED));
assertThat(respBody.toFuture().get(), equalTo("Testing123"));
} finally {
requester.closeAsync().toFuture().get();
}
}
use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class AbstractH2DuplexHandlerTest method noDataFramesForEmptyBuffers.
@ParameterizedTest
@EnumSource(Variant.class)
void noDataFramesForEmptyBuffers(Variant variant) {
setUp(variant);
Buffer[] payload = { EMPTY_BUFFER, DEFAULT_ALLOCATOR.fromAscii("data"), EMPTY_BUFFER };
HttpMetaData msg;
switch(variant) {
case CLIENT_HANDLER:
StreamingHttpRequest request = newRequest(GET, "/", HTTP_2_0, HEADERS_FACTORY.newHeaders(), DEFAULT_ALLOCATOR, HEADERS_FACTORY);
request.payloadBody(from(payload));
msg = request;
break;
case SERVER_HANDLER:
StreamingHttpResponse response = newResponse(HttpResponseStatus.OK, HTTP_2_0, HEADERS_FACTORY.newHeaders(), DEFAULT_ALLOCATOR, HEADERS_FACTORY);
response.payloadBody(from(payload));
msg = response;
break;
default:
throw new IllegalStateException("Unexpected variant: " + variant);
}
channel.writeOutbound(msg);
verify(closeHandler).protocolPayloadBeginOutbound(any());
verify(closeHandler, never()).protocolPayloadEndOutbound(any(), any());
for (Buffer buffer : payload) {
channel.writeOutbound(buffer);
}
verify(closeHandler, never()).protocolPayloadEndOutbound(any(), any());
channel.writeOutbound(EmptyHttpHeaders.INSTANCE);
verify(closeHandler).protocolPayloadEndOutbound(any(), any());
Http2HeadersFrame headersFrame = channel.readOutbound();
assertThat("Unexpected endStream flag value at headers frame", headersFrame.isEndStream(), is(false));
assertEmptyDataFrame();
Http2DataFrame dataFrame = channel.readOutbound();
assertThat("Unexpected data", dataFrame.content().toString(US_ASCII), is("data"));
assertThat("Unexpected endStream flag value at data frame", dataFrame.isEndStream(), is(false));
assertEmptyDataFrame();
dataFrame = channel.readOutbound();
assertThat("Unexpected endStream flag value at last frame", dataFrame.isEndStream(), is(true));
assertThat("Unexpected outbound messages", channel.outboundMessages(), empty());
}
use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class AbstractHttpConnectionTest method requestShouldWriteFlatStreamToConnectionAndReadFlatStreamSplicedIntoResponseAndPayload.
@SuppressWarnings("unchecked")
@Test
void requestShouldWriteFlatStreamToConnectionAndReadFlatStreamSplicedIntoResponseAndPayload() throws Exception {
Buffer chunk1 = allocator.fromAscii("test");
Buffer chunk2 = allocator.fromAscii("payload");
Buffer chunk3 = allocator.fromAscii("payload");
HttpHeaders trailers = headersFactory.newEmptyTrailers();
HttpHeaders headers = headersFactory.newHeaders();
headers.add(TRANSFER_ENCODING, CHUNKED);
StreamingHttpRequest req = newTransportRequest(GET, "/foo", HTTP_1_1, headers, allocator, from(chunk1, chunk2, chunk3, trailers), false, headersFactory);
HttpResponseMetaData respMeta = newResponseMetaData(HTTP_1_1, OK, INSTANCE.newHeaders().add(CONTENT_TYPE, TEXT_PLAIN));
Publisher<Object> respFlat = from(respMeta, chunk1, chunk2, chunk3, trailers);
ArgumentCaptor<Publisher<Object>> reqFlatCaptor = ArgumentCaptor.forClass(Publisher.class);
when(reqResp.apply(reqFlatCaptor.capture())).thenReturn(respFlat);
Single<StreamingHttpResponse> responseSingle = http.request(req);
StreamingHttpResponse resp = awaitIndefinitelyNonNull(responseSingle);
assertThat(reqFlatCaptor.getValue().toFuture().get(), contains(req, chunk1, chunk2, chunk3, trailers));
assertThat(resp.status(), equalTo(OK));
assertThat(resp.version(), equalTo(HTTP_1_1));
assertThat(resp.headers().get(CONTENT_TYPE), equalTo(TEXT_PLAIN));
assertThat(resp.payloadBody().toFuture().get(), contains(chunk1, chunk2, chunk3));
}
Aggregations