use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project flink by apache.
the class Router method toString.
/**
* Returns visualized routing rules.
*/
@Override
public String toString() {
// Step 1/2: Dump routers and anyMethodRouter in order
int numRoutes = size();
List<String> methods = new ArrayList<String>(numRoutes);
List<String> patterns = new ArrayList<String>(numRoutes);
List<String> targets = new ArrayList<String>(numRoutes);
// For router
for (Entry<HttpMethod, MethodlessRouter<T>> e : routers.entrySet()) {
HttpMethod method = e.getKey();
MethodlessRouter<T> router = e.getValue();
aggregateRoutes(method.toString(), router.routes(), methods, patterns, targets);
}
// For anyMethodRouter
aggregateRoutes("*", anyMethodRouter.routes(), methods, patterns, targets);
// For notFound
if (notFound != null) {
methods.add("*");
patterns.add("*");
targets.add(targetToString(notFound));
}
// Step 2/2: Format the List into aligned columns: <method> <patterns> <target>
int maxLengthMethod = maxLength(methods);
int maxLengthPattern = maxLength(patterns);
String format = "%-" + maxLengthMethod + "s %-" + maxLengthPattern + "s %s\n";
int initialCapacity = (maxLengthMethod + 1 + maxLengthPattern + 1 + 20) * methods.size();
StringBuilder b = new StringBuilder(initialCapacity);
for (int i = 0; i < methods.size(); i++) {
String method = methods.get(i);
String pattern = patterns.get(i);
String target = targets.get(i);
b.append(String.format(format, method, pattern, target));
}
return b.toString();
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project flink by apache.
the class Router method allowedMethods.
/**
* Returns allowed methods for a specific URI.
*
* <p>For {@code OPTIONS *}, use {@link #allAllowedMethods()} instead of this method.
*/
public Set<HttpMethod> allowedMethods(String uri) {
QueryStringDecoder decoder = new QueryStringDecoder(uri);
String[] tokens = PathPattern.removeSlashesAtBothEnds(decoder.path()).split("/");
if (anyMethodRouter.anyMatched(tokens)) {
return allAllowedMethods();
}
Set<HttpMethod> ret = new HashSet<HttpMethod>(routers.size());
for (Map.Entry<HttpMethod, MethodlessRouter<T>> entry : routers.entrySet()) {
MethodlessRouter<T> router = entry.getValue();
if (router.anyMatched(tokens)) {
HttpMethod method = entry.getKey();
ret.add(method);
}
}
return ret;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project flink by apache.
the class RouterHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext channelHandlerContext, HttpRequest httpRequest) {
if (HttpHeaders.is100ContinueExpected(httpRequest)) {
channelHandlerContext.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE));
return;
}
// Route
HttpMethod method = httpRequest.getMethod();
QueryStringDecoder qsd = new QueryStringDecoder(httpRequest.uri());
RouteResult<?> routeResult = router.route(method, qsd.path(), qsd.parameters());
if (routeResult == null) {
respondNotFound(channelHandlerContext, httpRequest);
return;
}
routed(channelHandlerContext, routeResult, httpRequest);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project crate by crate.
the class HttpBlobHandler method possibleRedirect.
private boolean possibleRedirect(HttpRequest request, String index, String digest) {
HttpMethod method = request.method();
if (method.equals(HttpMethod.GET) || method.equals(HttpMethod.HEAD) || (method.equals(HttpMethod.PUT) && HttpUtil.is100ContinueExpected(request))) {
String redirectAddress;
try {
redirectAddress = blobService.getRedirectAddress(index, digest);
} catch (MissingHTTPEndpointException ex) {
simpleResponse(request, HttpResponseStatus.BAD_GATEWAY);
return true;
}
if (redirectAddress != null) {
LOGGER.trace("redirectAddress: {}", redirectAddress);
sendRedirect(request, activeScheme + redirectAddress);
return true;
}
}
return false;
}
Aggregations