List of usage examples for io.netty.handler.codec.http HttpMethod GET
HttpMethod GET
To view the source code for io.netty.handler.codec.http HttpMethod GET.
Click Source Link
From source file:com.king.platform.net.http.netty.requestbuilder.HttpClientWebSocketRequestBuilderImpl.java
License:Apache License
public HttpClientWebSocketRequestBuilderImpl(HttpClientCaller httpClientCaller, String uri, ConfMap confMap, Executor callbackExecutor) { super(HttpClientWebSocketRequestBuilder.class, httpClientCaller, HttpVersion.HTTP_1_1, HttpMethod.GET, uri, confMap, callbackExecutor);/*from www .j av a 2 s . c o m*/ this.defaultCallbackExecutor = callbackExecutor; autoPong(confMap.get(ConfKeys.WEB_SOCKET_AUTO_PONG)); autoCloseFrame(confMap.get(ConfKeys.WEB_SOCKET_AUTO_CLOSE_FRAME)); }
From source file:com.linecorp.armeria.client.http.SimpleHttpClientCodecTest.java
License:Apache License
@Test public void encodeRequestNoBody() { SimpleHttpRequest request = SimpleHttpRequestBuilder.forGet("/foo?q=foo&bar=baz") .header(HttpHeaderNames.ORIGIN, "localhost").build(); EncodeResult result = codec.encodeRequest(channel, SCHEME.sessionProtocol(), EXECUTE_METHOD, new Object[] { request }); assertTrue(result.isSuccess());// w ww . jav a 2 s.co m assertEquals(SCHEME, result.encodedScheme().get()); assertEquals("/foo", result.encodedPath().get()); assertEquals("www.github.com", result.encodedHost().get()); FullHttpRequest fullHttpRequest = (FullHttpRequest) result.content(); assertEquals(HttpVersion.HTTP_1_1, fullHttpRequest.protocolVersion()); assertEquals("/foo?q=foo&bar=baz", fullHttpRequest.uri()); assertEquals(HttpMethod.GET, fullHttpRequest.method()); assertEquals("localhost", fullHttpRequest.headers().get(HttpHeaderNames.ORIGIN)); }
From source file:com.linecorp.armeria.client.http.SimpleHttpClientCodecTest.java
License:Apache License
@Test public void encodeRequestWithBody() { SimpleHttpRequest request = SimpleHttpRequestBuilder.forGet("/foo?q=foo&bar=baz") .content("lorem ipsum foo bar", StandardCharsets.UTF_8).header(HttpHeaderNames.ORIGIN, "localhost") .build();//from w w w.j a v a 2s. com EncodeResult result = codec.encodeRequest(channel, SCHEME.sessionProtocol(), EXECUTE_METHOD, new Object[] { request }); assertTrue(result.isSuccess()); assertEquals(SCHEME, result.encodedScheme().get()); assertEquals("/foo", result.encodedPath().get()); assertEquals("www.github.com", result.encodedHost().get()); FullHttpRequest fullHttpRequest = (FullHttpRequest) result.content(); assertEquals(HttpVersion.HTTP_1_1, fullHttpRequest.protocolVersion()); assertEquals("/foo?q=foo&bar=baz", fullHttpRequest.uri()); assertEquals(HttpMethod.GET, fullHttpRequest.method()); assertEquals("localhost", fullHttpRequest.headers().get(HttpHeaderNames.ORIGIN)); assertEquals("lorem ipsum foo bar", new String(ByteBufUtil.getBytes(fullHttpRequest.content()), StandardCharsets.UTF_8)); }
From source file:com.linecorp.armeria.client.http.SimpleHttpRequestBuilder.java
License:Apache License
/** * Returns a {@link SimpleHttpRequestBuilder} for a GET request to the given URI, * for setting additional HTTP parameters as needed. *//*from w w w . j a v a 2s . com*/ public static SimpleHttpRequestBuilder forGet(String uri) { return createRequestBuilder(uri, HttpMethod.GET); }
From source file:com.linecorp.armeria.client.http.SimpleHttpRequestBuilderTest.java
License:Apache License
@Test public void defaults() { SimpleHttpRequest request = SimpleHttpRequestBuilder.forGet("/path").build(); assertEquals("/path", request.uri().toString()); assertEquals(HttpMethod.GET, request.method()); assertTrue(request.headers().isEmpty()); assertEquals(0, request.content().length); }
From source file:com.linecorp.armeria.client.http.SimpleHttpRequestBuilderTest.java
License:Apache License
@Test public void httpMethods() { assertEquals(HttpMethod.GET, SimpleHttpRequestBuilder.forGet("/path").build().method()); assertEquals(HttpMethod.POST, SimpleHttpRequestBuilder.forPost("/path").build().method()); assertEquals(HttpMethod.PUT, SimpleHttpRequestBuilder.forPut("/path").build().method()); assertEquals(HttpMethod.PATCH, SimpleHttpRequestBuilder.forPatch("/path").build().method()); assertEquals(HttpMethod.DELETE, SimpleHttpRequestBuilder.forDelete("/path").build().method()); assertEquals(HttpMethod.HEAD, SimpleHttpRequestBuilder.forHead("/path").build().method()); assertEquals(HttpMethod.OPTIONS, SimpleHttpRequestBuilder.forOptions("/path").build().method()); }
From source file:com.linecorp.armeria.server.http.file.HttpFileServiceInvocationHandler.java
License:Apache License
@Override public void invoke(ServiceInvocationContext ctx, Executor blockingTaskExecutor, Promise<Object> promise) throws Exception { final HttpRequest req = ctx.originalRequest(); if (req.method() != HttpMethod.GET) { respond(ctx, promise, HttpResponseStatus.METHOD_NOT_ALLOWED, 0, ERROR_MIME_TYPE, Unpooled.wrappedBuffer(CONTENT_METHOD_NOT_ALLOWED)); return;//from w ww . ja va 2 s. com } final String path = normalizePath(ctx.mappedPath()); if (path == null) { respond(ctx, promise, HttpResponseStatus.NOT_FOUND, 0, ERROR_MIME_TYPE, Unpooled.wrappedBuffer(CONTENT_NOT_FOUND)); return; } Entry entry = getEntry(path); long lastModifiedMillis; if ((lastModifiedMillis = entry.lastModifiedMillis()) == 0) { boolean found = false; if (path.charAt(path.length() - 1) == '/') { // Try index.html if it was a directory access. entry = getEntry(path + "index.html"); if ((lastModifiedMillis = entry.lastModifiedMillis()) != 0) { found = true; } } if (!found) { respond(ctx, promise, HttpResponseStatus.NOT_FOUND, 0, ERROR_MIME_TYPE, Unpooled.wrappedBuffer(CONTENT_NOT_FOUND)); return; } } long ifModifiedSinceMillis = Long.MIN_VALUE; try { ifModifiedSinceMillis = req.headers().getTimeMillis(HttpHeaderNames.IF_MODIFIED_SINCE, Long.MIN_VALUE); } catch (Exception e) { // Ignore the ParseException, which is raised on malformed date. //noinspection ConstantConditions if (!(e instanceof ParseException)) { throw e; } } // HTTP-date does not have subsecond-precision; add 999ms to it. if (ifModifiedSinceMillis > Long.MAX_VALUE - 999) { ifModifiedSinceMillis = Long.MAX_VALUE; } else { ifModifiedSinceMillis += 999; } if (lastModifiedMillis < ifModifiedSinceMillis) { respond(ctx, promise, HttpResponseStatus.NOT_MODIFIED, lastModifiedMillis, entry.mimeType(), Unpooled.EMPTY_BUFFER); return; } respond(ctx, promise, HttpResponseStatus.OK, lastModifiedMillis, entry.mimeType(), entry.readContent(ctx.alloc())); }
From source file:com.linecorp.armeria.server.tracing.HttpTracingServiceInvocationHandlerTest.java
License:Apache License
@Test public void testGetTraceData() { DefaultHttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, ""); httpRequest.headers().add(traceHeaders()); ServiceInvocationContext ctx = mock(ServiceInvocationContext.class); when(ctx.originalRequest()).thenReturn(httpRequest); TraceData traceData = serviceInvocationHandler.getTraceData(ctx); assertThat(traceData.getSpanId(), is(testSpanId)); assertThat(traceData.getSample(), is(true)); }
From source file:com.linecorp.armeria.server.tracing.HttpTracingServiceInvocationHandlerTest.java
License:Apache License
@Test public void testGetTraceDataIfRequestIsNotContainTraceData() { DefaultHttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, ""); httpRequest.headers().add(emptyHttpHeaders()); ServiceInvocationContext ctx = mock(ServiceInvocationContext.class); when(ctx.originalRequest()).thenReturn(httpRequest); TraceData traceData = serviceInvocationHandler.getTraceData(ctx); assertThat(traceData.getSample(), is(nullValue())); assertThat(traceData.getSpanId(), is(nullValue())); }
From source file:com.linecorp.armeria.server.tracing.HttpTracingServiceInvocationHandlerTest.java
License:Apache License
private static void testGetTraceDataIfRequestIsNotSampled(HttpHeaders headers) { DefaultHttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, ""); httpRequest.headers().add(headers);//from w ww . ja v a 2 s. c om ServiceInvocationContext ctx = mock(ServiceInvocationContext.class); when(ctx.originalRequest()).thenReturn(httpRequest); TraceData traceData = serviceInvocationHandler.getTraceData(ctx); assertThat(traceData.getSpanId(), is(nullValue())); assertThat(traceData.getSample(), is(false)); }