@Override public String getRequestMethod() { return request.getMethod().getName(); }
private String getMsg(Class<?> handlerClass, String type, Context context) { return "Default production error handler used to render " + type + ", please add a " + handlerClass.getName() + " instance to your application " + "(method: " + context.getRequest().getMethod() + ", uri: " + context.getRequest().getRawUri() + ")"; }
@Override public void handle(Context context) throws Exception { HttpMethod method = context.getRequest().getMethod(); if (method.isOptions() && !handlers.containsKey(HttpMethod.OPTIONS)) { List<String> parts = new ArrayList<>(Collections2.transform(handlers.keySet(), HttpMethod::getName)); Collections.sort(parts); String methods = JOINER.join(parts); context.getResponse().getHeaders().add(HttpHeaderConstants.ALLOW, methods); context.getResponse().status(200).send(); } else { Handler handler = handlers.get(method); if (handler != null) { context.insert(handler); return; } if (method.isHead()) { Handler getHandler = handlers.get(HttpMethod.GET); if (getHandler != null) { context.insert(getHandler); return; } } NO_METHOD_HANDLER.handle(context); } }
private static boolean isFormAvailable(Request request, TypedData body) { HttpMethod method = request.getMethod(); return body != null && body.getContentType().isForm() && (method.isPost() || method.isPut()); }
request.maybeGet(UserId.class).map(Types::cast), request.getTimestamp(), request.getMethod(), request.getRawUri(), request.getProtocol(),
@SuppressWarnings("deprecation") public static <T> void connect(final Context context, String path, int maxLength, final WebSocketHandler<T> handler) { PublicAddress publicAddress = context.get(PublicAddress.class); URI address = publicAddress.get(context); URI httpPath = address.resolve(path); URI wsPath; try { wsPath = new URI("ws", httpPath.getUserInfo(), httpPath.getHost(), httpPath.getPort(), httpPath.getPath(), httpPath.getQuery(), httpPath.getFragment()); } catch (URISyntaxException e) { throw uncheck(e); } WebSocketServerHandshakerFactory factory = new WebSocketServerHandshakerFactory(wsPath.toString(), null, false, maxLength); Request request = context.getRequest(); HttpMethod method = valueOf(request.getMethod().getName()); FullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, request.getUri()); nettyRequest.headers().add(SEC_WEBSOCKET_VERSION, request.getHeaders().get(SEC_WEBSOCKET_VERSION)); nettyRequest.headers().add(SEC_WEBSOCKET_KEY, request.getHeaders().get(SEC_WEBSOCKET_KEY)); final WebSocketServerHandshaker handshaker = factory.newHandshaker(nettyRequest); final DirectChannelAccess directChannelAccess = context.getDirectChannelAccess(); final Channel channel = directChannelAccess.getChannel(); if (!channel.config().isAutoRead()) { channel.config().setAutoRead(true); } handshaker.handshake(channel, nettyRequest).addListener(new HandshakeFutureListener<>(context, handshaker, handler)); }
private void servePath(final Context context, final Path file) throws Exception { readAttributes(file, cacheMetadata, attributes -> { if (attributes == null) { context.next(); } else if (attributes.isRegularFile()) { if (context.getRequest().getMethod().isGet()) { sendFile(context, file, attributes); } else { context.clientError(405); } } else if (attributes.isDirectory()) { if (context.getRequest().getMethod().isGet()) { maybeSendFile(context, file, 0); } else { context.clientError(405); } } else { context.next(); } }); }
@SuppressWarnings("deprecation") public static Form parseForm(Context context, TypedData body, MultiValueMap<String, String> base) throws RuntimeException { Request request = context.getRequest(); HttpMethod method = io.netty.handler.codec.http.HttpMethod.valueOf(request.getMethod().getName()); HttpRequest nettyRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, method, request.getUri()); nettyRequest.headers().add(HttpHeaderNames.CONTENT_TYPE, body.getContentType().toString());
public void handle(Context context) { ratpack.http.HttpMethod requestMethod = context.getRequest().getMethod(); if (requestMethod == method || requestMethod.name(method.getName())) { context.next(); } else if (requestMethod.isOptions()) { Response response = context.getResponse(); response.getHeaders().add(HttpHeaderConstants.ALLOW, method); response.status(200).send(); } else { context.clientError(405); } } }
if (HttpMethod.GET.equals(request.getMethod())) { if (!oXsrfValue.isPresent()) { Cookie cookie = response.cookie(config.getCookieName(), randomString(64));