Search in sources :

Example 1 with HttpMethod

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project elasticsearch by elastic.

the class Netty4HttpServerTransport method buildCorsConfig.

// package private for testing
static Netty4CorsConfig buildCorsConfig(Settings settings) {
    if (SETTING_CORS_ENABLED.get(settings) == false) {
        return Netty4CorsConfigBuilder.forOrigins().disable().build();
    }
    String origin = SETTING_CORS_ALLOW_ORIGIN.get(settings);
    final Netty4CorsConfigBuilder builder;
    if (Strings.isNullOrEmpty(origin)) {
        builder = Netty4CorsConfigBuilder.forOrigins();
    } else if (origin.equals(ANY_ORIGIN)) {
        builder = Netty4CorsConfigBuilder.forAnyOrigin();
    } else {
        Pattern p = RestUtils.checkCorsSettingForRegex(origin);
        if (p == null) {
            builder = Netty4CorsConfigBuilder.forOrigins(RestUtils.corsSettingAsArray(origin));
        } else {
            builder = Netty4CorsConfigBuilder.forPattern(p);
        }
    }
    if (SETTING_CORS_ALLOW_CREDENTIALS.get(settings)) {
        builder.allowCredentials();
    }
    String[] strMethods = Strings.tokenizeToStringArray(SETTING_CORS_ALLOW_METHODS.get(settings), ",");
    HttpMethod[] methods = Arrays.asList(strMethods).stream().map(HttpMethod::valueOf).toArray(size -> new HttpMethod[size]);
    return builder.allowedRequestMethods(methods).maxAge(SETTING_CORS_MAX_AGE.get(settings)).allowedRequestHeaders(Strings.tokenizeToStringArray(SETTING_CORS_ALLOW_HEADERS.get(settings), ",")).shortCircuit().build();
}
Also used : Pattern(java.util.regex.Pattern) Netty4CorsConfigBuilder(org.elasticsearch.http.netty4.cors.Netty4CorsConfigBuilder) HttpMethod(io.netty.handler.codec.http.HttpMethod)

Example 2 with HttpMethod

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project vert.x by eclipse.

the class HttpServerRequestImpl method setExpectMultipart.

@Override
public HttpServerRequest setExpectMultipart(boolean expect) {
    synchronized (conn) {
        checkEnded();
        if (expect) {
            if (decoder == null) {
                String contentType = request.headers().get(HttpHeaders.Names.CONTENT_TYPE);
                if (contentType != null) {
                    HttpMethod method = request.getMethod();
                    String lowerCaseContentType = contentType.toLowerCase();
                    boolean isURLEncoded = lowerCaseContentType.startsWith(HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED);
                    if ((lowerCaseContentType.startsWith(HttpHeaders.Values.MULTIPART_FORM_DATA) || isURLEncoded) && (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.PATCH) || method.equals(HttpMethod.DELETE))) {
                        decoder = new HttpPostRequestDecoder(new NettyFileUploadDataFactory(conn.vertx(), this, () -> uploadHandler), request);
                    }
                }
            }
        } else {
            decoder = null;
        }
        return this;
    }
}
Also used : HttpPostRequestDecoder(io.netty.handler.codec.http.multipart.HttpPostRequestDecoder) HttpMethod(io.netty.handler.codec.http.HttpMethod)

Example 3 with HttpMethod

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project hadoop by apache.

the class WebHdfsHandler method handle.

public void handle(ChannelHandlerContext ctx, HttpRequest req) throws IOException, URISyntaxException {
    String op = params.op();
    HttpMethod method = req.getMethod();
    if (PutOpParam.Op.CREATE.name().equalsIgnoreCase(op) && method == PUT) {
        onCreate(ctx);
    } else if (PostOpParam.Op.APPEND.name().equalsIgnoreCase(op) && method == POST) {
        onAppend(ctx);
    } else if (GetOpParam.Op.OPEN.name().equalsIgnoreCase(op) && method == GET) {
        onOpen(ctx);
    } else if (GetOpParam.Op.GETFILECHECKSUM.name().equalsIgnoreCase(op) && method == GET) {
        onGetFileChecksum(ctx);
    } else if (PutOpParam.Op.CREATE.name().equalsIgnoreCase(op) && method == OPTIONS) {
        allowCORSOnCreate(ctx);
    } else {
        throw new IllegalArgumentException("Invalid operation " + op);
    }
}
Also used : HttpMethod(io.netty.handler.codec.http.HttpMethod)

Example 4 with HttpMethod

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method handleRequest_gracefully_handles_some_null_args.

@DataProvider(value = { "true   |   false   |   false", "false  |   true    |   false", "false  |   false   |   true", "true   |   true    |   true" }, splitBy = "\\|")
@Test
public void handleRequest_gracefully_handles_some_null_args(boolean endpointIsNull, boolean methodIsNull, boolean matchingPathTemplateIsNull) {
    // given
    int statusCode = 242;
    int statusCodeXXValue = 2;
    long elapsedTimeMillis = 42;
    Endpoint endpoint = (endpointIsNull) ? null : endpointMock;
    doReturn(endpoint).when(httpStateMock).getEndpointForExecution();
    String expectedEndpointClass = (endpointIsNull) ? "NONE" : endpoint.getClass().getName();
    HttpMethod method = (methodIsNull) ? null : httpMethod;
    doReturn(method).when(requestInfoMock).getMethod();
    String expectedMethodName = (methodIsNull) ? "NONE" : method.name();
    String pathTemplate = (matchingPathTemplateIsNull) ? null : matchingPathTemplate;
    doReturn(pathTemplate).when(httpStateMock).getMatchingPathTemplate();
    String expectedPathTemplate = (matchingPathTemplateIsNull) ? "NONE" : pathTemplate;
    // when
    handler.handleRequest(requestInfoMock, responseInfoMock, httpStateMock, statusCode, statusCodeXXValue, elapsedTimeMillis);
    // then
    verify(metricMetadataMock).forBuilder(requestTimerBuilderMock);
    verify(dimensionConfiguratorMock).setupMetricWithDimensions(timerBuilderTaggerMock, requestInfoMock, responseInfoMock, httpStateMock, statusCode, statusCodeXXValue, elapsedTimeMillis, endpoint, expectedEndpointClass, expectedMethodName, expectedPathTemplate);
    verify(timerBuilderTaggerMock).createOrGet(metricRegistryMock);
    verify(timerMock).update(elapsedTimeMillis, TimeUnit.MILLISECONDS);
}
Also used : Endpoint(com.nike.riposte.server.http.Endpoint) Matchers.anyString(org.mockito.Matchers.anyString) Endpoint(com.nike.riposte.server.http.Endpoint) HttpMethod(io.netty.handler.codec.http.HttpMethod) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 5 with HttpMethod

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project riposte by Nike-Inc.

the class AllowAllTheThingsCORSFilterTest method filterRequestLastChunkWithOptionalShortCircuitResponse_always_returns_null.

@DataProvider(value = { "OPTIONS", "GET", "POST", "PUT" }, splitBy = "\\|")
@Test
public void filterRequestLastChunkWithOptionalShortCircuitResponse_always_returns_null(String httpMethodString) {
    // given
    HttpMethod method = HttpMethod.valueOf(httpMethodString);
    doReturn(method).when(requestMock).getMethod();
    // when
    Pair<RequestInfo<?>, Optional<ResponseInfo<?>>> result = filter.filterRequestLastChunkWithOptionalShortCircuitResponse(requestMock, ctxMock);
    // then
    assertThat(result).isNull();
}
Also used : Optional(java.util.Optional) RequestInfo(com.nike.riposte.server.http.RequestInfo) HttpMethod(io.netty.handler.codec.http.HttpMethod) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Aggregations

HttpMethod (io.netty.handler.codec.http.HttpMethod)83 Test (org.junit.Test)44 HttpRequest (io.netty.handler.codec.http.HttpRequest)24 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)23 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)20 URI (java.net.URI)15 IOException (java.io.IOException)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 DefaultHttpClient (org.jocean.http.client.impl.DefaultHttpClient)11 TestChannelCreator (org.jocean.http.client.impl.TestChannelCreator)11 TestChannelPool (org.jocean.http.client.impl.TestChannelPool)11 DefaultSignalClient (org.jocean.http.rosa.impl.DefaultSignalClient)11 HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)11 Subscription (rx.Subscription)11 Action2 (rx.functions.Action2)11 ByteBuf (io.netty.buffer.ByteBuf)10 HttpVersion (io.netty.handler.codec.http.HttpVersion)10 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)9 Map (java.util.Map)9 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)8