@SafeVarargs public final NettyHttpClientRequestBuilder withHeaders(Pair<String, Object>... headers) { return withHeaders(Arrays.asList(headers)); }
@DataProvider(value = { "STANDARD_ENDPOINT", "PROXY_ENDPOINT" }) @Test public void endpoints_should_be_reachable_with_barely_valid_initial_line_length_values( EndpointTypeScenario scenario ) throws Exception { // given String barelyAcceptableUri = generateUriForInitialLineLength( HttpMethod.GET, scenario.matchingPathBase, CUSTOM_REQUEST_DECODER_CONFIG.maxInitialLineLength() ); Pair<String, Object> barelyAcceptableHeader = generateHeaderForHeaderLineLength(CUSTOM_REQUEST_DECODER_CONFIG.maxHeaderSize()); NettyHttpClientRequestBuilder request = request() .withMethod(HttpMethod.GET) .withUri(barelyAcceptableUri) .withHeaders(barelyAcceptableHeader); // when NettyHttpClientResponse serverResponse = request.execute(scenario.serverPort, incompleteCallTimeoutMillis); // then assertThat(serverResponse.statusCode).isEqualTo(200); assertThat(serverResponse.payload).isEqualTo(scenario.successfulResponsePayload); }
@DataProvider(value = { "STANDARD_ENDPOINT", "PROXY_ENDPOINT" }) @Test public void endpoints_should_throw_decode_exception_for_single_header_that_is_too_long( EndpointTypeScenario scenario ) throws Exception { // given Pair<String, Object> tooLongHeader = generateHeaderForHeaderLineLength( CUSTOM_REQUEST_DECODER_CONFIG.maxHeaderSize() + 1 ); NettyHttpClientRequestBuilder request = request() .withMethod(HttpMethod.GET) .withUri(scenario.matchingPathBase) .withHeaders(tooLongHeader); // when NettyHttpClientResponse serverResponse = request.execute(scenario.serverPort, incompleteCallTimeoutMillis); // then assertTooLongFrameErrorResponse(serverResponse, EXPECTED_TOO_LONG_FRAME_HEADER_API_ERROR); // The EXPECTED_TOO_LONG_FRAME_HEADER_API_ERROR check above should have verified 431 status code, but do a // sanity check here just for test readability. assertThat(serverResponse.statusCode).isEqualTo(431); }
@DataProvider(value = { "STANDARD_ENDPOINT", "PROXY_ENDPOINT" }) @Test public void endpoints_should_throw_decode_exception_for_multiple_headers_that_are_too_long_when_summed( EndpointTypeScenario scenario ) throws Exception { // given Pair<String, Object> halfMaxLengthHeader = generateHeaderForHeaderLineLength( "foo", CUSTOM_REQUEST_DECODER_CONFIG.maxHeaderSize() / 2 ); Pair<String, Object> halfMaxLengthHeaderPlusOne = generateHeaderForHeaderLineLength( "bar", (CUSTOM_REQUEST_DECODER_CONFIG.maxHeaderSize() / 2) + 1 ); NettyHttpClientRequestBuilder request = request() .withMethod(HttpMethod.GET) .withUri(scenario.matchingPathBase) .withHeaders(halfMaxLengthHeader, halfMaxLengthHeaderPlusOne); // when NettyHttpClientResponse serverResponse = request.execute(scenario.serverPort, incompleteCallTimeoutMillis); // then assertTooLongFrameErrorResponse(serverResponse, EXPECTED_TOO_LONG_FRAME_HEADER_API_ERROR); // The EXPECTED_TOO_LONG_FRAME_HEADER_API_ERROR check above should have verified 431 status code, but do a // sanity check here just for test readability. assertThat(serverResponse.statusCode).isEqualTo(431); }