Search in sources :

Example 36 with HttpHeaders

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));
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) URI(java.net.URI) Test(org.junit.Test)

Example 37 with HttpHeaders

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));
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) URI(java.net.URI) Test(org.junit.Test)

Example 38 with HttpHeaders

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();
    }
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) HttpResponseStatus(org.asynchttpclient.HttpResponseStatus) Request(org.asynchttpclient.Request) HttpResponseBodyPart(org.asynchttpclient.HttpResponseBodyPart) Test(org.junit.Test)

Example 39 with HttpHeaders

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);
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders)

Example 40 with HttpHeaders

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();
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) BString(org.ballerinalang.model.values.BString) Map(java.util.Map) BMap(org.ballerinalang.model.values.BMap)

Aggregations

HttpHeaders (io.netty.handler.codec.http.HttpHeaders)286 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)149 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)83 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)73 Test (org.junit.Test)68 Test (org.junit.jupiter.api.Test)57 Test (org.testng.annotations.Test)51 HttpRequest (io.netty.handler.codec.http.HttpRequest)43 HttpResponse (io.netty.handler.codec.http.HttpResponse)40 AsciiString (io.netty.util.AsciiString)29 ByteBuf (io.netty.buffer.ByteBuf)27 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)27 BStruct (org.ballerinalang.model.values.BStruct)26 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)22 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)22 HttpServletResponse (javax.servlet.http.HttpServletResponse)20 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)19 Cookie (io.netty.handler.codec.http.cookie.Cookie)19 BValue (org.ballerinalang.model.values.BValue)19 ChannelPromise (io.netty.channel.ChannelPromise)18