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


Java HttpVersion.HTTP_1_0屬性代碼示例

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


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

示例1: build

public static HttpContext build(HttpRequestVisitor visitor) {
    HttpContext context = new HttpContext();
    context.remoteAddress = visitor.visitRemoteAddress();
    context.uri = visitor.visitURI();
    context.terms = visitor.visitTerms();
    context.requestMethod = visitor.visitHttpMethod();
    context.httpHeaders = visitor.visitHttpHeaders();
    context.httpParams = visitor.visitHttpParams();

    // TODO : if exclude GET or not ?
    //
    context.httpBody = visitor.visitHttpBody();

    if (visitor.visitHttpVersion() == HttpVersion.HTTP_1_1 &&
            HttpConstants.HEADER_CONNECTION_CLOSE.equals(context.httpHeaders.get(HttpConstants.HEADER_CONNECTION)))
        context.isKeepAlive = false;

    if (visitor.visitHttpVersion() == HttpVersion.HTTP_1_0 &&
            !HttpConstants.HEADER_CONNECTION_KEEPALIVE.equalsIgnoreCase(context.httpHeaders.get(HttpConstants.HEADER_CONNECTION)))
        context.isKeepAlive = false;

    return context;
}
 
開發者ID:gugemichael,項目名稱:nesty,代碼行數:23,代碼來源:HttpContext.java

示例2: testBuildContent

@Test
public void testBuildContent()
    throws Exception {
  HttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "www.google.com");
  RecordedHttpRequestBuilder recordedHttpRequestBuilder = new RecordedHttpRequestBuilder(nettyRequest);

  String charset = "UTF-8";
  String str1 = "first content";
  HttpContent httpContent1 = new DefaultHttpContent(Unpooled.copiedBuffer(str1.getBytes(charset)));
  recordedHttpRequestBuilder.appendHttpContent(httpContent1);
  String str2 = "second content";
  HttpContent httpContent2 = new DefaultHttpContent(Unpooled.copiedBuffer(str2.getBytes(charset)));
  recordedHttpRequestBuilder.appendHttpContent(httpContent2);

  String lastStr = "Last chunk";
  HttpContent lastContent = new DefaultLastHttpContent(Unpooled.copiedBuffer(lastStr.getBytes(charset)));
  recordedHttpRequestBuilder.appendHttpContent(lastContent);

  RecordedHttpRequest recordedHttpRequest = recordedHttpRequestBuilder.build();
  Assert
      .assertEquals((str1 + str2 + lastStr).getBytes(charset), recordedHttpRequest.getHttpBody().getContent(charset));
}
 
開發者ID:linkedin,項目名稱:flashback,代碼行數:22,代碼來源:RecordedHttpRequestBuilderTest.java

示例3: testBuild

@Test
public void testBuild()
    throws IOException {
  HttpResponse httpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_0, HttpResponseStatus.GATEWAY_TIMEOUT);
  RecordedHttpResponseBuilder recordedHttpResponseBuilder = new RecordedHttpResponseBuilder(httpResponse);

  String charset = "UTF-8";
  String str1 = "Hello world";
  HttpContent httpContent1 = new DefaultHttpContent(Unpooled.copiedBuffer(str1.getBytes(charset)));
  recordedHttpResponseBuilder.appendHttpContent(httpContent1);
  String str2 = "second content";
  HttpContent httpContent2 = new DefaultHttpContent(Unpooled.copiedBuffer(str2.getBytes(charset)));
  recordedHttpResponseBuilder.appendHttpContent(httpContent2);

  String lastStr = "Last chunk";
  HttpContent lastContent = new DefaultLastHttpContent(Unpooled.copiedBuffer(lastStr.getBytes(charset)));
  recordedHttpResponseBuilder.appendHttpContent(lastContent);
  RecordedHttpResponse recordedHttpResponse = recordedHttpResponseBuilder.build();
  Assert.assertEquals(recordedHttpResponse.getStatus(), HttpResponseStatus.GATEWAY_TIMEOUT.code());
  Assert.assertEquals((str1 + str2 + lastStr).getBytes(charset),
      recordedHttpResponse.getHttpBody().getContent(charset));
}
 
開發者ID:linkedin,項目名稱:flashback,代碼行數:22,代碼來源:RecordedHttpResponseBuilderTest.java

示例4: protocolVersion

@Override
public HttpVersion protocolVersion() {
  if (version == HttpVer.HTTP_1_0) {
    return HttpVersion.HTTP_1_0;
  } else {
    return HttpVersion.HTTP_1_1;
  }
}
 
開發者ID:monkeyWie,項目名稱:proxyee-down,代碼行數:8,代碼來源:HttpRequestInfo.java

示例5: testHttpsReq

@Test
public void testHttpsReq() {
	RequestKeyGenerator keyGen = new RequestKeyGenerator(
			s_appConfig);
	DefaultFullHttpRequest req1 = new DefaultFullHttpRequest(
			HttpVersion.HTTP_1_0, HttpMethod.GET, "/v1/s1");

	assertTrue(keyGen.generateKey(req1).startsWith("/v1/s1"));

	HttpHeaders.setHost(req1, "s.ebay.com");
	assertTrue(keyGen.generateKey(req1).startsWith(
			"https://s.ebay.com/v1/s1"));
}
 
開發者ID:eBay,項目名稱:ServiceCOLDCache,代碼行數:13,代碼來源:RequestKeyGeneratorTest.java

示例6: testURIMatchOnly

@Test
public void testURIMatchOnly() throws IOException {
	AppConfiguration appConfig = new AppConfiguration(new ConfigLoader(),
			"./src/test/resources/testuserconfig.json");
	appConfig.init();
	RequestKeyGenerator keyGen = new RequestKeyGenerator(appConfig);

	ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
	buffer.writeBytes("{\"fromDate\":1464251112185,\"toDate\":1464337512185}"
			.getBytes());
	DefaultFullHttpRequest req1 = new DefaultFullHttpRequest(
			HttpVersion.HTTP_1_0, HttpMethod.GET,
			"http://test.ebay.com/v1/s1", buffer);

	String key1 = keyGen.generateKey(req1);

	buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
	buffer.writeBytes("{\"fromDate\":1464251113750,\"toDate\":1464337513750}"
			.getBytes());
	DefaultFullHttpRequest req2 = new DefaultFullHttpRequest(
			HttpVersion.HTTP_1_0, HttpMethod.GET,
			"http://test.ebay.com/v1/s1", buffer);

	String key2 = keyGen.generateKey(req2);
	assertEquals(key1, key2);

	HttpHeaders.setContentLength(req2, 758);
	key2 = keyGen.generateKey(req2);
	assertEquals(key1, key2);

	appConfig.put("uriMatchOnly", null);
	keyGen = new RequestKeyGenerator(appConfig);
	key1 = keyGen.generateKey(req1);
	key2 = keyGen.generateKey(req2);

	assertNotEquals(key1, key2);
}
 
開發者ID:eBay,項目名稱:ServiceCOLDCache,代碼行數:37,代碼來源:RequestKeyGeneratorTest.java

示例7: fromVersion

private HttpVersion fromVersion(Message.Version version) {
  switch (version) {
    case HTTP_1_0: return HttpVersion.HTTP_1_0;
    case HTTP_1_1: return HttpVersion.HTTP_1_1;
    default: return HttpVersion.HTTP_1_1;
  }
}
 
開發者ID:RestNEXT,項目名稱:restnext,代碼行數:7,代碼來源:ServerHandler.java

示例8: createTestRequest

private Request createTestRequest()
{
    Request r = new Request(new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "/test/path/here"), new RouteResolver(null));
    r.addHeader("testHeader_1", "test1");
    r.addHeader("testHeader_1", "test2");
    r.addHeader("testHeader_1", "test3");
    r.addHeader("testHeader_2", "test4");
    return r;
}
 
開發者ID:PearsonEducation,項目名稱:Docussandra,代碼行數:9,代碼來源:SecurityPluginPreproccessorTest.java

示例9: testBuildHttpMethod

@Test
public void testBuildHttpMethod() {
  HttpRequest nettyRequest =
      new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "http://www.google.com");
  RecordedHttpRequestBuilder recordedHttpRequestBuilder = new RecordedHttpRequestBuilder(nettyRequest);
  RecordedHttpRequest recordedHttpRequest = recordedHttpRequestBuilder.build();
  Assert.assertEquals(recordedHttpRequest.getMethod(), HttpMethod.GET.toString());
}
 
開發者ID:linkedin,項目名稱:flashback,代碼行數:8,代碼來源:RecordedHttpRequestBuilderTest.java

示例10: testBuildAbsoluteUri

@Test
public void testBuildAbsoluteUri() {
  String uri = "http://www.google.com";
  HttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, uri);
  RecordedHttpRequestBuilder recordedHttpRequestBuilder = new RecordedHttpRequestBuilder(nettyRequest);
  RecordedHttpRequest recordedHttpRequest = recordedHttpRequestBuilder.build();
  Assert.assertEquals(recordedHttpRequest.getUri().toString(), uri);
}
 
開發者ID:linkedin,項目名稱:flashback,代碼行數:8,代碼來源:RecordedHttpRequestBuilderTest.java

示例11: testBuildRelativeUri

@Test
public void testBuildRelativeUri() {
  String uri = "finance";
  HttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, uri);
  nettyRequest.headers().set(HttpHeaders.Names.HOST, "www.google.com/");
  RecordedHttpRequestBuilder recordedHttpRequestBuilder = new RecordedHttpRequestBuilder(nettyRequest);
  RecordedHttpRequest recordedHttpRequest = recordedHttpRequestBuilder.build();
  Assert.assertEquals(recordedHttpRequest.getUri().toString(), "https://www.google.com/finance");
}
 
開發者ID:linkedin,項目名稱:flashback,代碼行數:9,代碼來源:RecordedHttpRequestBuilderTest.java

示例12: testBuildWithUnsupportedUri

@Test(expectedExceptions = IllegalStateException.class)
public void testBuildWithUnsupportedUri() {
  String uri = "http://example.com/file[/].html";
  HttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, uri);
  RecordedHttpRequestBuilder recordedHttpRequestBuilder = new RecordedHttpRequestBuilder(nettyRequest);
  recordedHttpRequestBuilder.build();
}
 
開發者ID:linkedin,項目名稱:flashback,代碼行數:7,代碼來源:RecordedHttpRequestBuilderTest.java

示例13: testBuildWithUriTwoLegs

@Test
public void testBuildWithUriTwoLegs() {
  HttpRequest nettyRequest1 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "finance");
  RecordedHttpRequestBuilder recordedHttpRequestBuilder = new RecordedHttpRequestBuilder(nettyRequest1);
  HttpRequest nettyRequest2 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "google.com");
  nettyRequest2.headers().set(HttpHeaders.Names.HOST, "www.google.com/");
  recordedHttpRequestBuilder.addHeaders(nettyRequest2);
  RecordedHttpRequest recordedHttpRequest = recordedHttpRequestBuilder.build();
  Assert.assertEquals(recordedHttpRequest.getUri().toString(), "https://www.google.com/finance");
}
 
開發者ID:linkedin,項目名稱:flashback,代碼行數:10,代碼來源:RecordedHttpRequestBuilderTest.java

示例14: testBuildWithUriTwoLegsIllegalUri

@Test(expectedExceptions = IllegalStateException.class)
public void testBuildWithUriTwoLegsIllegalUri() {
  HttpRequest nettyRequest1 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "file[/].html");
  RecordedHttpRequestBuilder recordedHttpRequestBuilder = new RecordedHttpRequestBuilder(nettyRequest1);
  HttpRequest nettyRequest2 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "google.com");
  nettyRequest2.headers().set(HttpHeaders.Names.HOST, "www.google.com/");
  recordedHttpRequestBuilder.addHeaders(nettyRequest2);
  recordedHttpRequestBuilder.build();
}
 
開發者ID:linkedin,項目名稱:flashback,代碼行數:9,代碼來源:RecordedHttpRequestBuilderTest.java


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