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();
}
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;
}
}
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);
}
}
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);
}
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();
}
Aggregations