use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project selenium_java by sergueik.
the class UtilsTest method whenRequestedTypeIsNotHTMLThenNotChangingURLRequest.
@Test
public void whenRequestedTypeIsNotHTMLThenNotChangingURLRequest() throws URISyntaxException {
URI uri = new URI("http://tenniskafe.com");
HttpHeaders httpHeaders = mock(HttpHeaders.class);
when(httpHeaders.get("Accept")).thenReturn("application/json");
HttpRequest httpRequest = mock(HttpRequest.class);
when(httpRequest.getUri()).thenReturn("http://google.com");
when(httpRequest.headers()).thenReturn(httpHeaders);
assertFalse(Utils.isUrlChangingRequest(uri, httpRequest));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project selenium_java by sergueik.
the class UtilsTest method whenTheHostIsTheSameThenNotChangingURLRequest.
@Test
public void whenTheHostIsTheSameThenNotChangingURLRequest() throws URISyntaxException {
URI uri = new URI("http://tenniskafe.com");
HttpHeaders httpHeaders = mock(HttpHeaders.class);
when(httpHeaders.get("Accept")).thenReturn("application/json");
HttpRequest httpRequest = mock(HttpRequest.class);
when(httpRequest.getUri()).thenReturn("http://tenniskafe.com/atp");
when(httpRequest.headers()).thenReturn(httpHeaders);
assertFalse(Utils.isUrlChangingRequest(uri, httpRequest));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project tutorials by eugenp.
the class AsyncHttpClientTestCase method givenHttpClient_executeAsyncGetRequestWithAsyncHandler.
@Test
public void givenHttpClient_executeAsyncGetRequestWithAsyncHandler() {
// execute an unbound GET request
Request unboundGetRequest = Dsl.get("http://www.baeldung.com").build();
HTTP_CLIENT.executeRequest(unboundGetRequest, new AsyncHandler<Integer>() {
int responseStatusCode = -1;
@Override
public State onStatusReceived(HttpResponseStatus responseStatus) {
responseStatusCode = responseStatus.getStatusCode();
return State.CONTINUE;
}
@Override
public State onHeadersReceived(HttpHeaders headers) {
return State.CONTINUE;
}
@Override
public State onBodyPartReceived(HttpResponseBodyPart bodyPart) {
return State.CONTINUE;
}
@Override
public void onThrowable(Throwable t) {
}
@Override
public Integer onCompleted() {
assertEquals(200, responseStatusCode);
return responseStatusCode;
}
});
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project ballerina by ballerina-lang.
the class AbstractHTTPAction method setOutboundReqHeaders.
private void setOutboundReqHeaders(HTTPCarbonMessage outboundRequest, int port, String host) {
HttpHeaders headers = outboundRequest.getHeaders();
setHostHeader(host, port, headers);
setOutboundUserAgent(headers);
removeConnectionHeader(headers);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project ballerina by ballerina-lang.
the class MultipartDataSource method writeBodyPartHeaders.
/**
* Write body part headers to output stream.
*
* @param writer Represent the outputstream writer
* @param bodyPart Represent ballerina body part
* @throws IOException When an error occurs while writing body part headers
*/
private void writeBodyPartHeaders(Writer writer, BStruct bodyPart) throws IOException {
HttpHeaders httpHeaders;
if (bodyPart.getNativeData(ENTITY_HEADERS) != null) {
httpHeaders = (HttpHeaders) bodyPart.getNativeData(ENTITY_HEADERS);
} else {
httpHeaders = new DefaultHttpHeaders();
bodyPart.addNativeData(ENTITY_HEADERS, httpHeaders);
}
String contentType = MimeUtil.getContentTypeWithParameters(bodyPart);
httpHeaders.set(HttpHeaderNames.CONTENT_TYPE.toString(), contentType);
String contentDisposition = MimeUtil.getContentDisposition(bodyPart);
if (!contentDisposition.isEmpty()) {
httpHeaders.set(HttpHeaderNames.CONTENT_DISPOSITION.toString(), contentDisposition);
}
if (bodyPart.getStringField(CONTENT_ID_INDEX) != null && !bodyPart.getStringField(CONTENT_ID_INDEX).isEmpty()) {
httpHeaders.set(CONTENT_ID, bodyPart.getStringField(CONTENT_ID_INDEX));
}
Iterator<Map.Entry<String, String>> iterator = httpHeaders.iteratorAsString();
while (iterator.hasNext()) {
Map.Entry<String, String> entry = iterator.next();
writer.write(entry.getKey());
writer.write(COLON);
writer.write(SPACE);
writer.write(entry.getValue());
writer.write(CRLF);
}
// Mark the end of the headers for this body part
writer.write(CRLF);
writer.flush();
}
Aggregations