@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof HandlerWrapper)) { return false; } HandlerWrapper that = (HandlerWrapper) o; if (uriTemplate != null ? !uriTemplate.equals(that.uriTemplate) : that.uriTemplate != null) { return false; } return !(httpMethod != null ? !httpMethod.equals(that.httpMethod) : that.httpMethod != null); }
@Override protected boolean isContentAlwaysEmpty(@SuppressWarnings("unused") HttpResponse msg) { method = queue.poll(); return HttpMethod.HEAD.equals(method) || super.isContentAlwaysEmpty(msg); } }
private static boolean isPreflightRequest(final HttpRequest request) { final HttpHeaders headers = request.headers(); return request.method().equals(OPTIONS) && headers.contains(HttpHeaderNames.ORIGIN) && headers.contains(HttpHeaderNames.ACCESS_CONTROL_REQUEST_METHOD); }
@Override protected void channelRead0(ChannelHandlerContext ctx, HttpRequest request) throws Exception { final Channel channel = ctx.channel(); final boolean keepAlive = HttpUtil.isKeepAlive(request); final HttpVersion httpRequestVersion = request.protocolVersion(); final String origin = request.headers().get(HttpHeaderNames.ORIGIN); // to allow for future changes, let's be at least a little strict in what we accept here. if (HttpMethod.OPTIONS.equals(request.method())) { writeResponse(channel, keepAlive, httpRequestVersion, HttpResponseStatus.OK, origin); return; } else if (!HttpMethod.POST.equals(request.method())) { writeResponse(channel, keepAlive, httpRequestVersion, HttpResponseStatus.METHOD_NOT_ALLOWED, origin); return; } final boolean correctPath = "/gelf".equals(request.uri()); if (correctPath && request instanceof FullHttpRequest) { final FullHttpRequest fullHttpRequest = (FullHttpRequest) request; final ByteBuf buffer = fullHttpRequest.content(); // send on to raw message handler writeResponse(channel, keepAlive, httpRequestVersion, HttpResponseStatus.ACCEPTED, origin); ctx.fireChannelRead(buffer.retain()); } else { writeResponse(channel, keepAlive, httpRequestVersion, HttpResponseStatus.NOT_FOUND, origin); } }
private void handleMessage(FullHttpRequest req, UUID sessionId, QueryStringDecoder queryDecoder, ChannelHandlerContext ctx) throws IOException { String origin = req.headers().get(HttpHeaderNames.ORIGIN); if (queryDecoder.parameters().containsKey("disconnect")) { ClientHead client = clientsBox.get(sessionId); client.onChannelDisconnect(); ctx.channel().writeAndFlush(new XHRPostMessage(origin, sessionId)); } else if (HttpMethod.POST.equals(req.method())) { onPost(sessionId, ctx, origin, req.content()); } else if (HttpMethod.GET.equals(req.method())) { onGet(sessionId, ctx, origin); } else if (HttpMethod.OPTIONS.equals(req.method())) { onOptions(sessionId, ctx, origin); } else { log.error("Wrong {} method invocation for {}", req.method(), sessionId); sendError(ctx); } }
@Override public boolean equals(Object o) { if (!(o instanceof DefaultHttpRequest)) { return false; } DefaultHttpRequest other = (DefaultHttpRequest) o; return method().equals(other.method()) && uri().equalsIgnoreCase(other.uri()) && super.equals(o); }
LOG.trace("Session: {} got valid HTTP request:\n{}", sessionUuidAttr.get().toString(), httpRequest.headers().toString()); if (httpRequest.getMethod().equals(HttpMethod.POST)) { String uri = httpRequest.getUri(); AbstractCommand cp = (AbstractCommand) commandFactory.getCommandProcessor(uri);
this.charset = checkNotNull(charset, "charset"); this.factory = checkNotNull(factory, "factory"); if (HttpMethod.TRACE.equals(request.method())) { throw new ErrorDataEncoderException("Cannot create a Encoder if request is a TRACE");
/** * Returns the content length of the specified web socket message. If the * specified message is not a web socket message, {@code -1} is returned. */ private static int getWebSocketContentLength(HttpMessage message) { // WebSocket messages have constant content-lengths. HttpHeaders h = message.headers(); if (message instanceof HttpRequest) { HttpRequest req = (HttpRequest) message; if (HttpMethod.GET.equals(req.method()) && h.contains(HttpHeaderNames.SEC_WEBSOCKET_KEY1) && h.contains(HttpHeaderNames.SEC_WEBSOCKET_KEY2)) { return 8; } } else if (message instanceof HttpResponse) { HttpResponse res = (HttpResponse) message; if (res.status().code() == 101 && h.contains(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN) && h.contains(HttpHeaderNames.SEC_WEBSOCKET_LOCATION)) { return 16; } } // Not a web socket message return -1; }
if (HttpMethod.TRACE.equals(method)) {
@Override public HttpResponse clientToProxyRequest(HttpObject httpObject) { if (httpObject instanceof HttpRequest) { HttpRequest httpRequest = (HttpRequest) httpObject; String url = getFullUrl(httpRequest); for (BlacklistEntry entry : blacklistedUrls) { if (HttpMethod.CONNECT.equals(httpRequest.getMethod()) && entry.getHttpMethodPattern() == null) { // do not allow CONNECTs to be blacklisted unless a method pattern is explicitly specified continue; } if (entry.matches(url, httpRequest.getMethod().name())) { HttpResponseStatus status = HttpResponseStatus.valueOf(entry.getStatusCode()); HttpResponse resp = new DefaultFullHttpResponse(httpRequest.getProtocolVersion(), status); HttpHeaders.setContentLength(resp, 0L); return resp; } } } return null; } }
public NettyHttpResponse(final ChannelHandlerContext ctx, final boolean keepAlive, final ResteasyProviderFactory providerFactory, final HttpMethod method) { outputHeaders = new MultivaluedMapImpl<String, Object>(); this.method = method; os = (method == null || !method.equals(HttpMethod.HEAD)) ? new ChunkOutputStream(this, ctx, 1000) : null; //[RESTEASY-1627] this.ctx = ctx; this.keepAlive = keepAlive; this.providerFactory = providerFactory; }
public DefaultHttpResponse getEmptyHttpResponse() { DefaultFullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(getStatus())); if (method == null || !method.equals(HttpMethod.HEAD)) //[RESTEASY-1627] { res.headers().add(HttpHeaderNames.CONTENT_LENGTH, EMPTY_CONTENT_LENGTH); } transformResponseHeaders(res); return res; }
public static ChannelHandlerDelegate create(HttpRequest httpRequest, ChannelMediator channelMediator, Map<Protocol, List<ConnectionFlowStep>> connectionFlowRegistry) { if (HttpMethod.CONNECT.equals(httpRequest.getMethod())) { List<ConnectionFlowStep> connectionFlow = connectionFlowRegistry.get(Protocol.HTTPS); ConnectionFlowProcessor httpsConnectionFlowProcessor = new ConnectionFlowProcessor(channelMediator, httpRequest, connectionFlow); channelMediator.initializeProxyModeController(httpRequest); return new HttpsChannelHandlerDelegate(channelMediator, httpsConnectionFlowProcessor); } else { List<ConnectionFlowStep> connectionFlow = connectionFlowRegistry.get(Protocol.HTTP); ConnectionFlowProcessor httpConnectionFlowProcessor = new ConnectionFlowProcessor(channelMediator, httpRequest, connectionFlow); channelMediator.initializeProxyModeController(httpRequest); return new HttpChannelHandlerDelegate(channelMediator, httpConnectionFlowProcessor); } }
responseContent.setLength(0); if (request.getMethod().equals(HttpMethod.POST)) {