本文整理匯總了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;
}
示例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));
}
示例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));
}
示例4: protocolVersion
@Override
public HttpVersion protocolVersion() {
if (version == HttpVer.HTTP_1_0) {
return HttpVersion.HTTP_1_0;
} else {
return HttpVersion.HTTP_1_1;
}
}
示例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"));
}
示例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);
}
示例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;
}
}
示例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;
}
示例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());
}
示例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);
}
示例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");
}
示例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();
}
示例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");
}
示例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();
}