use of org.apache.hc.core5.http.message.BasicHttpResponse in project httpcomponents-core by apache.
the class TestDefaultH2ResponseConverter method testConvertFromMessageConnectionHeader.
@Test
public void testConvertFromMessageConnectionHeader() throws Exception {
final HttpResponse response = new BasicHttpResponse(200);
response.addHeader("Connection", "Keep-Alive");
final DefaultH2ResponseConverter converter = new DefaultH2ResponseConverter();
Assertions.assertThrows(HttpException.class, () -> converter.convert(response), "Header 'Connection: Keep-Alive' is illegal for HTTP/2 messages");
}
use of org.apache.hc.core5.http.message.BasicHttpResponse in project httpcomponents-core by apache.
the class TestDefaultH2ResponseConverter method testConvertFromMessageBasic.
@Test
public void testConvertFromMessageBasic() throws Exception {
final HttpResponse response = new BasicHttpResponse(200);
response.addHeader("custom123", "Value");
final DefaultH2ResponseConverter converter = new DefaultH2ResponseConverter();
final List<Header> headers = converter.convert(response);
Assertions.assertNotNull(headers);
Assertions.assertEquals(2, headers.size());
final Header header1 = headers.get(0);
Assertions.assertEquals(":status", header1.getName());
Assertions.assertEquals("200", header1.getValue());
final Header header2 = headers.get(1);
Assertions.assertEquals("custom123", header2.getName());
Assertions.assertEquals("Value", header2.getValue());
}
use of org.apache.hc.core5.http.message.BasicHttpResponse in project httpcomponents-core by apache.
the class EchoHandler method handleRequest.
@Override
public void handleRequest(final HttpRequest request, final EntityDetails entityDetails, final ResponseChannel responseChannel, final HttpContext context) throws HttpException, IOException {
final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
responseChannel.sendResponse(response, entityDetails, context);
}
use of org.apache.hc.core5.http.message.BasicHttpResponse in project httpcomponents-core by apache.
the class ReactiveEchoProcessor method processRequest.
@Override
public void processRequest(final HttpRequest request, final EntityDetails entityDetails, final ResponseChannel responseChannel, final HttpContext context, final Publisher<ByteBuffer> requestBody, final Callback<Publisher<ByteBuffer>> responseBodyFuture) throws HttpException, IOException {
if (new BasicHeader(HttpHeaders.EXPECT, HeaderElements.CONTINUE).equals(request.getHeader(HttpHeaders.EXPECT))) {
responseChannel.sendInformation(new BasicHttpResponse(100), context);
}
responseChannel.sendResponse(new BasicHttpResponse(200), new BasicEntityDetails(-1, ContentType.APPLICATION_OCTET_STREAM), context);
responseBodyFuture.execute(requestBody);
}
use of org.apache.hc.core5.http.message.BasicHttpResponse in project httpcomponents-core by apache.
the class ReactiveRandomProcessor method processRequest.
@Override
public void processRequest(final HttpRequest request, final EntityDetails entityDetails, final ResponseChannel responseChannel, final HttpContext context, final Publisher<ByteBuffer> requestBody, final Callback<Publisher<ByteBuffer>> responseBodyCallback) throws HttpException, IOException {
final String method = request.getMethod();
if (!"GET".equalsIgnoreCase(method) && !"HEAD".equalsIgnoreCase(method) && !"POST".equalsIgnoreCase(method) && !"PUT".equalsIgnoreCase(method)) {
throw new MethodNotSupportedException(method + " not supported by " + getClass().getName());
}
final URI uri;
try {
uri = request.getUri();
} catch (final URISyntaxException ex) {
throw new ProtocolException(ex.getMessage(), ex);
}
final String path = uri.getPath();
final int slash = path.lastIndexOf('/');
if (slash != -1) {
final String payload = path.substring(slash + 1);
final long n;
if (!payload.isEmpty()) {
try {
n = Long.parseLong(payload);
} catch (final NumberFormatException ex) {
throw new ProtocolException("Invalid request path: " + path);
}
} else {
// random length, but make sure at least something is sent
n = 1 + (int) (Math.random() * 79.0);
}
if (new BasicHeader(HttpHeaders.EXPECT, HeaderElements.CONTINUE).equals(request.getHeader(HttpHeaders.EXPECT))) {
responseChannel.sendInformation(new BasicHttpResponse(100), context);
}
final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
final Flowable<ByteBuffer> stream = ReactiveTestUtils.produceStream(n);
final String hash = ReactiveTestUtils.getStreamHash(n);
response.addHeader("response-hash-code", hash);
final BasicEntityDetails basicEntityDetails = new BasicEntityDetails(n, ContentType.APPLICATION_OCTET_STREAM);
responseChannel.sendResponse(response, basicEntityDetails, context);
responseBodyCallback.execute(stream);
} else {
throw new ProtocolException("Invalid request path: " + path);
}
}
Aggregations