List of usage examples for io.netty.handler.codec.http HttpMethod OPTIONS
HttpMethod OPTIONS
To view the source code for io.netty.handler.codec.http HttpMethod OPTIONS.
Click Source Link
From source file:org.restexpress.route.RouteResolverTest.java
License:Apache License
@Test public void shouldSendAllowedMethodsForGetRoute() { FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "/foo/bar/bar23.json?value=ignored"); httpRequest.headers().add("Host", "testing-host"); Request request = new Request(httpRequest, null); try {//from ww w. j a va2s . co m resolver.resolve(request); } catch (MethodNotAllowedException e) { List<HttpMethod> allowed = e.getAllowedMethods(); assertEquals(1, allowed.size()); assertTrue(allowed.contains(HttpMethod.GET)); } }
From source file:org.thingsplode.synapse.endpoint.handlers.HttpRequestHandler.java
License:Apache License
@Override protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest httpRequest) throws Exception { //todo: support for API keys ///endpoints/json?api_key=565656 try {//w w w . j av a 2 s .c o m // Handle a bad request. if (!httpRequest.decoderResult().isSuccess()) { HttpResponseHandler.sendError(ctx, HttpResponseStatus.BAD_REQUEST, "Could not decode request.", httpRequest); return; } if (httpRequest.method().equals(HttpMethod.HEAD) || httpRequest.method().equals(HttpMethod.PATCH) || httpRequest.method().equals(HttpMethod.TRACE) || httpRequest.method().equals(HttpMethod.CONNECT) || httpRequest.method().equals(HttpMethod.OPTIONS)) { HttpResponseHandler.sendError(ctx, HttpResponseStatus.FORBIDDEN, "Method forbidden (The following are not supported: HEAD, PATCH, TRACE, CONNECT, OPTIONS).", httpRequest); return; } //check websocket upgrade request String upgradeHeader = httpRequest.headers().get(HttpHeaderNames.UPGRADE); if (!Util.isEmpty(upgradeHeader) && UPGRADE_TO_WEBSOCKET.equalsIgnoreCase(upgradeHeader)) { //case websocket upgrade request is detected -> Prepare websocket handshake upgradeToWebsocket(ctx, httpRequest); return; } else { //case simple http request Request request = new Request(prepareHeader(ctx, httpRequest)); //no information about the object type / it will be processed in a later stage //todo: with requestbodytype header value early deserialization would be possible, however not beneficial in routing cases request.setBody(httpRequest.content()); ctx.fireChannelRead(request); } } catch (Exception ex) { logger.error("Channel read error: " + ex.getMessage(), ex); HttpResponseHandler.sendError(ctx, HttpResponseStatus.INTERNAL_SERVER_ERROR, ex.getClass().getSimpleName() + ": " + ex.getMessage(), httpRequest); } }
From source file:org.waarp.openr66.protocol.http.rest.test.HttpTestRestR66Client.java
License:Open Source License
protected static RestFuture options(Channel channel, String uri) throws HttpInvalidAuthenticationException { logger.debug("Send query"); String key = null, value = null; if (HttpTestR66PseudoMain.config.REST_AUTHENTICATED) { key = userAuthent;//from w ww.j ava 2 s.co m value = keyAuthent; } RestFuture future = clientHelper.sendQuery(HttpTestR66PseudoMain.config, channel, HttpMethod.OPTIONS, host, uri, key, value, null, null); logger.debug("Query sent"); return future; }
From source file:reactor.ipc.netty.http.client.HttpClientFormEncoder.java
License:Open Source License
/** * @param factory the factory used to create InterfaceHttpData * @param request the request to encode/*w ww .j ava 2 s . c o m*/ * @param multipart True if the FORM is a ENCTYPE="multipart/form-data" * @param charset the charset to use as default * @param encoderMode the mode for the encoder to use. See {@link EncoderMode} for the * details. * * @throws NullPointerException for request or charset or factory * @throws ErrorDataEncoderException if the request is not a POST */ HttpClientFormEncoder(HttpDataFactory factory, HttpRequest request, boolean multipart, Charset charset, EncoderMode encoderMode) throws ErrorDataEncoderException { if (factory == null) { throw new NullPointerException("factory"); } if (request == null) { throw new NullPointerException("request"); } if (charset == null) { throw new NullPointerException("charset"); } HttpMethod method = request.method(); if (!(method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.PATCH) || method.equals(HttpMethod.OPTIONS))) { throw new ErrorDataEncoderException("Cannot create a Encoder if not a POST"); } this.request = request; this.charset = charset; this.newCharset = charset; this.factory = factory; this.progressFlux = DirectProcessor.create(); this.cleanOnTerminate = true; this.newMode = encoderMode; this.newMultipart = multipart; // Fill default values bodyListDatas = new ArrayList<>(); // default mode isLastChunk = false; isLastChunkSent = false; isMultipart = multipart; multipartHttpDatas = new ArrayList<>(); this.encoderMode = encoderMode; if (isMultipart) { initDataMultipart(); } }