當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpVersion.HTTP_1_1屬性代碼示例

本文整理匯總了Java中io.netty.handler.codec.http.HttpVersion.HTTP_1_1屬性的典型用法代碼示例。如果您正苦於以下問題:Java HttpVersion.HTTP_1_1屬性的具體用法?Java HttpVersion.HTTP_1_1怎麽用?Java HttpVersion.HTTP_1_1使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在io.netty.handler.codec.http.HttpVersion的用法示例。


在下文中一共展示了HttpVersion.HTTP_1_1屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testBasicAuthenticationFailure

@Test
public void testBasicAuthenticationFailure() throws Exception {
    Configuration config = TestConfiguration.createMinimalConfigurationForTest();

    BasicAuthLogin auth = new BasicAuthLogin();
    auth.setUsername("test");
    auth.setPassword("test2");
    DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/login");
    request.content().writeBytes(JsonSerializer.getObjectMapper().writeValueAsBytes(auth));

    TestHttpQueryDecoder decoder = new TestHttpQueryDecoder(config);
    decoder.decode(null, request, results);
    Assert.assertEquals(1, results.size());
    Object result = results.iterator().next();
    Assert.assertEquals(BasicAuthLoginRequest.class, result.getClass());

    BasicAuthLoginRequestHandler handler = new BasicAuthLoginRequestHandler(config);
    CaptureChannelHandlerContext ctx = new CaptureChannelHandlerContext();
    handler.channelRead(ctx, result);
    Assert.assertNotNull(ctx.msg);
    Assert.assertTrue(ctx.msg instanceof DefaultFullHttpResponse);
    DefaultFullHttpResponse response = (DefaultFullHttpResponse) ctx.msg;
    Assert.assertEquals(HttpResponseStatus.UNAUTHORIZED, response.getStatus());
    Assert.assertTrue(response.headers().contains(Names.CONTENT_TYPE));
    Assert.assertEquals(Constants.JSON_TYPE, response.headers().get(Names.CONTENT_TYPE));
}
 
開發者ID:NationalSecurityAgency,項目名稱:qonduit,代碼行數:26,代碼來源:BasicAuthLoginRequestHandlerTest.java

示例2: newResponse

/**
 * Returns a full HTTP response with the specified status, content type, and custom headers.
 *
 * <p>Headers should be specified as a map of strings. For example, to allow CORS, add the
 * following key and value: "access-control-allow-origin", "http://foo.example"
 *
 * <p>If content type or content length are passed in as custom headers, they will be ignored.
 * Instead, content type will be as specified by the parameter contentType and content length will
 * be the length of the parameter contentLength.
 */
public static FullHttpResponse newResponse(
    HttpResponseStatus status,
    ByteBuf payload,
    ContentType contentType,
    Map<String, String> customHeaders) {
  FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, payload);

  if (customHeaders != null) {
    for (Map.Entry<String, String> entry : customHeaders.entrySet()) {
      response.headers().set(entry.getKey(), entry.getValue());
    }
  }

  response.headers().set(CONTENT_TYPE, contentType.value);
  response.headers().setInt(CONTENT_LENGTH, payload.readableBytes());

  return response;
}
 
開發者ID:Nordstrom,項目名稱:xrpc,代碼行數:28,代碼來源:Recipes.java

示例3: shouldHandlerRequestAndResponse

@Test
public void shouldHandlerRequestAndResponse() {
    inboundChannel.pipeline().addLast(handler);

    DefaultFullHttpRequest req = new DefaultFullHttpRequest(
            HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
    inboundChannel.write(req);

    assertEquals(1, inboundChannel.outboundMessages().size());

    Object outboundReq = inboundChannel.outboundMessages().poll();
    assertTrue(outboundReq instanceof ByteBuf);
    assertEquals("GET / HTTP/1.1\r\n\r\n", new String(readBytes((ByteBuf) outboundReq)));

    DefaultFullHttpResponse resp = new DefaultFullHttpResponse(
            HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    assertFalse(inboundChannel.writeInbound(resp));

    assertEquals(1, outboundChannel.outboundMessages().size());
    assertEquals(resp, outboundChannel.outboundMessages().poll());

    resp.release();
}
 
開發者ID:chhsiao90,項目名稱:nitmproxy,代碼行數:23,代碼來源:Http1BackendHandlerTest.java

示例4: shouldPendingRequests

@Test
public void shouldPendingRequests() {
    inboundChannel.pipeline().addLast(handler);

    DefaultFullHttpRequest req = new DefaultFullHttpRequest(
            HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
    // First request
    inboundChannel.write(req.retain());

    assertEquals(1, inboundChannel.outboundMessages().size());
    assertTrue(inboundChannel.outboundMessages().poll() instanceof ByteBuf);

    // Second request
    inboundChannel.write(req);

    // Should pending second request
    assertTrue(inboundChannel.outboundMessages().isEmpty());
}
 
開發者ID:chhsiao90,項目名稱:nitmproxy,代碼行數:18,代碼來源:Http1BackendHandlerTest.java

示例5: onOutboundError

@Override
protected void onOutboundError(Throwable err) {

	if (!channel().isActive()) {
		super.onOutboundError(err);
		return;
	}

	discreteRemoteClose(err);
	if (markSentHeaders()) {
		log.error("Error starting response. Replying error status", err);

		HttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
				HttpResponseStatus.INTERNAL_SERVER_ERROR);
		response.headers()
		        .setInt(HttpHeaderNames.CONTENT_LENGTH, 0)
		        .set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
		channel().writeAndFlush(response)
		         .addListener(ChannelFutureListener.CLOSE);
		return;
	}

	markSentBody();
	channel().writeAndFlush(EMPTY_BUFFER)
	         .addListener(ChannelFutureListener.CLOSE);
}
 
開發者ID:reactor,項目名稱:reactor-netty,代碼行數:26,代碼來源:HttpServerOperations.java

示例6: testIsProxyRequest

@Test
public void testIsProxyRequest() throws IOException{
	AppConfiguration appConfig = new AppConfiguration(new ConfigLoader(),
			null);
	appConfig.init();
	PolicyManager policyManager = mock(PolicyManager.class);
	NettyRequestProxyFilter filter = new NettyRequestProxyFilter(
			policyManager, appConfig);
	
	DefaultFullHttpRequest req = new DefaultFullHttpRequest(
			HttpVersion.HTTP_1_1, HttpMethod.GET, "/version");
	assertTrue(filter.isProxyRequest(req));
	assertRequest(filter, req, false, "localhost:32876");
	assertRequest(filter, req, false, "127.0.0.1:32876");
	assertRequest(filter, req, true, "localhost:32877");
	assertRequest(filter, req, true, "localhost");
	assertRequest(filter, req, true, "127.0.0.1");
	assertRequest(filter, req, true, "trace.vip.ebay.com");
	assertRequest(filter, req, true, "");
}
 
開發者ID:eBay,項目名稱:ServiceCOLDCache,代碼行數:20,代碼來源:NettyRequestProxyFilterTest.java

示例7: writeResponse

private void writeResponse(final Channel channel, final HttpResponseStatus statusCode) {
    // Convert the response content to a ChannelBuffer.
    final ByteBuf buf = copiedBuffer(responseContent.toString(), CharsetUtil.UTF_8);
    responseContent.setLength(0);
    // Decide whether to close the connection or not.
    final boolean close = HttpHeaders.Values.CLOSE.equalsIgnoreCase(request.headers().get(CONNECTION)) ||
            request.getProtocolVersion().equals(HttpVersion.HTTP_1_0) && !HttpHeaders.Values.KEEP_ALIVE.equalsIgnoreCase(request.headers().get(CONNECTION));
    // Build the response object.
    final FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, statusCode, buf);
    response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");
    if (!close) {
        // There's no need to add 'Content-Length' header if this is the last response.
        response.headers().set(CONTENT_LENGTH, buf.readableBytes());
    }
    // Write the response.
    final ChannelFuture future = channel.writeAndFlush(response);
    // Close the connection after the write operation is done if necessary.
    if (close) {
        future.addListener(ChannelFutureListener.CLOSE);
    }
}
 
開發者ID:MissionCriticalCloud,項目名稱:cosmic,代碼行數:21,代碼來源:HttpUploadServerHandler.java

示例8: startProxyServerWithFilterAnsweringStatusCode

private void startProxyServerWithFilterAnsweringStatusCode(int statusCode) {
    final HttpResponseStatus status = HttpResponseStatus.valueOf(statusCode);
    HttpFiltersSource filtersSource = new HttpFiltersSourceAdapter() {
        @Override
        public HttpFilters filterRequest(HttpRequest originalRequest) {
            return new HttpFiltersAdapter(originalRequest) {
                @Override
                public HttpResponse clientToProxyRequest(HttpObject httpObject) {
                    return new DefaultHttpResponse(HttpVersion.HTTP_1_1, status);
                }
            };
        }
    };

    proxyServer = DefaultHttpProxyServer.bootstrap()
            .withPort(0)
            .withFiltersSource(filtersSource)
            .start();
}
 
開發者ID:wxyzZ,項目名稱:little_mitm,代碼行數:19,代碼來源:DirectRequestTest.java

示例9: writeResponse

private void writeResponse(Channel channel, Response response, HttpRequest httpRequest) {
    ByteBuf buf = Unpooled.copiedBuffer(JsonCodec.encodeResponse(response), CharsetUtil.UTF_8);
    FullHttpResponse httpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buf);

    String contentType = "text/html; charset=UTF-8";
    httpResponse.headers().set(HttpHeaderNames.CONTENT_TYPE, contentType);

    boolean close = httpRequest.headers().contains(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE, true)
            || httpRequest.protocolVersion().equals(HttpVersion.HTTP_1_0)
            || !httpRequest.headers().contains(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE, true);

    if (!close) {
        httpResponse.headers().set(HttpHeaderNames.CONTENT_LENGTH, buf.readableBytes());
    }

    ChannelFuture future = channel.writeAndFlush(response);
    future.addListener(ChannelFutureListener.CLOSE);
}
 
開發者ID:haiger,項目名稱:dqueue,代碼行數:18,代碼來源:HttpHandler.java

示例10: testSuggestPostWithValidTypeAndQuery

@Test
public void testSuggestPostWithValidTypeAndQuery() throws Exception {
    // @formatter:off
    String content = 
    "{\n" +
    "    \"type\": \"metrics\",\n" +
    "    \"q\": \"sys.cpu.user\"\n" +
    "}";
    // @formatter:on
    decoder = new TestHttpQueryDecoder(config);
    DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
            "/api/suggest");
    request.content().writeBytes(content.getBytes());
    addCookie(request);
    decoder.decode(null, request, results);
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(SuggestRequest.class, results.iterator().next().getClass());
    SuggestRequest suggest = (SuggestRequest) results.iterator().next();
    Assert.assertEquals("metrics", suggest.getType());
    Assert.assertEquals("sys.cpu.user", suggest.getQuery().get());
    Assert.assertEquals(25, suggest.getMax());
    suggest.validate();
}
 
開發者ID:NationalSecurityAgency,項目名稱:timely,代碼行數:23,代碼來源:HttpRequestDecoderTest.java

示例11: sendRequest

private void sendRequest(HttpUrl url) {
  start = System.nanoTime();
  total = 0;
  HttpRequest request = new DefaultFullHttpRequest(
      HttpVersion.HTTP_1_1, HttpMethod.GET, url.encodedPath());
  request.headers().set(HttpHeaders.Names.HOST, url.host());
  request.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);
  channel.writeAndFlush(request);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:NettyHttpClient.java

示例12: sendError

private void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
    ByteBuf content = Unpooled.copiedBuffer("Failure: " + status + "\r\n",
            CharsetUtil.UTF_8);
    FullHttpResponse response = new DefaultFullHttpResponse(
            HttpVersion.HTTP_1_1, status, content);
    response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8");

    // Close the connection as soon as the error message is sent.
    ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:10,代碼來源:HttpServer.java

示例13: sendRedirect

public void sendRedirect(ChannelHandlerContext ctx, String newUri) {
   FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.FOUND);
   response.headers().set(HttpHeaders.Names.LOCATION, newUri);

   // Close the connection as soon as the error message is sent.
   ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
}
 
開發者ID:SpreadServe,項目名稱:TFWebSock,代碼行數:7,代碼來源:NettyHttpFileHandler.java

示例14: createHttpCarbonMessage

public HTTPCarbonMessage createHttpCarbonMessage(String method) {
    HTTPCarbonMessage httpCarbonMessage = null;
    switch (method) {
        case "GET": {
            httpCarbonMessage = new HTTPCarbonMessage(
                    new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, ""));
            break;
        }
        case "PUT": {
            httpCarbonMessage = new HTTPCarbonMessage(
                    new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, ""));
            break;
        }
        case "PATCH": {
            httpCarbonMessage = new HTTPCarbonMessage(
                    new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PATCH, ""));
            break;
        }
        case "DELETE": {
            httpCarbonMessage = new HTTPCarbonMessage(
                    new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.DELETE, ""));
            break;
        }
        case "POST": {
            httpCarbonMessage = new HTTPCarbonMessage(
                    new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, ""));
            break;
        }
        default: {
            log.error("Invalid request type.");

            break;
        }
    }
    return httpCarbonMessage;
}
 
開發者ID:wso2-extensions,項目名稱:siddhi-io-http,代碼行數:36,代碼來源:HttpSink.java

示例15: newFullRequest

public static FullHttpRequest newFullRequest(
    HttpMethod method, String urlPath, ByteBuf payload, ContentType contentType) {
  FullHttpRequest request =
      new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, urlPath, payload);
  request.headers().set(CONTENT_TYPE, contentType.value);
  request.headers().setInt(CONTENT_LENGTH, payload.readableBytes());
  return request;
}
 
開發者ID:Nordstrom,項目名稱:xrpc,代碼行數:8,代碼來源:Recipes.java


注:本文中的io.netty.handler.codec.http.HttpVersion.HTTP_1_1屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。