Java 类io.vertx.core.http.HttpVersion 实例源码

项目:incubator-servicecomb-java-chassis    文件:WebsocketClientPool.java   
@Override
public HttpClientOptions createHttpClientOptions() {
  HttpVersion ver = ServiceRegistryConfig.INSTANCE.getHttpVersion();
  HttpClientOptions httpClientOptions = new HttpClientOptions();
  httpClientOptions.setProtocolVersion(ver);
  httpClientOptions.setConnectTimeout(ServiceRegistryConfig.INSTANCE.getConnectionTimeout());
  httpClientOptions.setIdleTimeout(ServiceRegistryConfig.INSTANCE.getIdleWatchTimeout());
  if (ver == HttpVersion.HTTP_2) {
    LOGGER.debug("service center ws client protocol version is HTTP/2");
    httpClientOptions.setHttp2ClearTextUpgrade(false);
  }
  if (ServiceRegistryConfig.INSTANCE.isSsl()) {
    LOGGER.debug("service center ws client performs requests over TLS");
    VertxTLSBuilder.buildHttpClientOptions(SSL_KEY, httpClientOptions);
  }
  return httpClientOptions;
}
项目:incubator-servicecomb-java-chassis    文件:HttpClientPool.java   
@Override
public HttpClientOptions createHttpClientOptions() {
  HttpVersion ver = ServiceRegistryConfig.INSTANCE.getHttpVersion();
  HttpClientOptions httpClientOptions = new HttpClientOptions();
  httpClientOptions.setProtocolVersion(ver);
  httpClientOptions.setConnectTimeout(ServiceRegistryConfig.INSTANCE.getConnectionTimeout());
  httpClientOptions.setIdleTimeout(ServiceRegistryConfig.INSTANCE.getIdleConnectionTimeout());
  if (ServiceRegistryConfig.INSTANCE.isProxyEnable()) {
    ProxyOptions proxy = new ProxyOptions();
    proxy.setHost(ServiceRegistryConfig.INSTANCE.getProxyHost());
    proxy.setPort(ServiceRegistryConfig.INSTANCE.getProxyPort());
    proxy.setUsername(ServiceRegistryConfig.INSTANCE.getProxyUsername());
    proxy.setPassword(ServiceRegistryConfig.INSTANCE.getProxyPasswd());
    httpClientOptions.setProxyOptions(proxy);
  }
  if (ver == HttpVersion.HTTP_2) {
    LOGGER.debug("service center client protocol version is HTTP/2");
    httpClientOptions.setHttp2ClearTextUpgrade(false);
  }
  if (ServiceRegistryConfig.INSTANCE.isSsl()) {
    LOGGER.debug("service center client performs requests over TLS");
    VertxTLSBuilder.buildHttpClientOptions(SSL_KEY, httpClientOptions);
  }
  return httpClientOptions;
}
项目:incubator-servicecomb-java-chassis    文件:TestServiceRegistryClientImpl.java   
@Test
public void testPrivateMethodCreateHttpClientOptions() {
  MicroserviceFactory microserviceFactory = new MicroserviceFactory();
  Microservice microservice = microserviceFactory.create("app", "ms");
  oClient.registerMicroservice(microservice);
  oClient.registerMicroserviceInstance(microservice.getInstance());
  new MockUp<ServiceRegistryConfig>() {
    @Mock
    public HttpVersion getHttpVersion() {
      return HttpVersion.HTTP_2;
    }

    @Mock
    public boolean isSsl() {
      return true;
    }
  };
  try {
    oClient.init();
    HttpClientOptions httpClientOptions = Deencapsulation.invoke(oClient, "createHttpClientOptions");
    Assert.assertNotNull(httpClientOptions);
    Assert.assertEquals(80, httpClientOptions.getDefaultPort());
  } catch (Exception e) {
    Assert.assertNotNull(e);
  }
}
项目:incubator-servicecomb-java-chassis    文件:FirstLineOfRequestElementTest.java   
@Test
public void getFormattedElement() {
  AccessLogParam param = new AccessLogParam();
  RoutingContext mockContext = Mockito.mock(RoutingContext.class);
  HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
  String uri = "/test/uri";

  param.setRoutingContext(mockContext);
  Mockito.when(mockContext.request()).thenReturn(request);
  Mockito.when(request.method()).thenReturn(HttpMethod.DELETE);
  Mockito.when(request.path()).thenReturn(uri);
  Mockito.when(request.version()).thenReturn(HttpVersion.HTTP_1_1);

  String result = ELEMENT.getFormattedElement(param);

  assertEquals("\"DELETE " + uri + " HTTP/1.1\"", result);
}
项目:incubator-servicecomb-java-chassis    文件:VersionOrProtocolElementTest.java   
@Test
public void getFormattedElement() {
  AccessLogParam param = new AccessLogParam();
  RoutingContext context = Mockito.mock(RoutingContext.class);
  HttpServerRequest request = Mockito.mock(HttpServerRequest.class);

  param.setRoutingContext(context);
  Mockito.when(context.request()).thenReturn(request);
  Mockito.when(request.version()).thenReturn(HttpVersion.HTTP_1_1);

  String result = new VersionOrProtocolElement().getFormattedElement(param);
  assertEquals("HTTP/1.1", result);

  Mockito.when(request.version()).thenReturn(HttpVersion.HTTP_1_0);
  result = new VersionOrProtocolElement().getFormattedElement(param);
  assertEquals("HTTP/1.0", result);

  Mockito.when(request.version()).thenReturn(HttpVersion.HTTP_2);
  result = new VersionOrProtocolElement().getFormattedElement(param);
  assertEquals("HTTP/2.0", result);
}
项目:vertx-web    文件:LoggerHandlerImpl.java   
@Override
public void handle(RoutingContext context) {
  // common logging data
  long timestamp = System.currentTimeMillis();
  String remoteClient = getClientAddress(context.request().remoteAddress());
  HttpMethod method = context.request().method();
  String uri = context.request().uri();
  HttpVersion version = context.request().version();

  if (immediate) {
    log(context, timestamp, remoteClient, version, method, uri);
  } else {
    context.addBodyEndHandler(v -> log(context, timestamp, remoteClient, version, method, uri));
  }

  context.next();

}
项目:wisdom    文件:HttpUtilsTest.java   
@Test
public void testIsKeepAlive() throws Exception {
    MultiMap headers = MultiMap.caseInsensitiveMultiMap();
    HttpServerRequest req = mock(HttpServerRequest.class);
    when(req.headers()).thenReturn(headers);

    // Connection header set.
    headers.add(HeaderNames.CONNECTION, HttpUtils.CLOSE);
    assertThat(HttpUtils.isKeepAlive(req)).isFalse();

    headers.add(HeaderNames.CONNECTION, HttpUtils.KEEP_ALIVE);
    assertThat(HttpUtils.isKeepAlive(req)).isTrue();

    // Unset connection header
    headers.clear();
    when(req.version()).thenReturn(HttpVersion.HTTP_1_1);
    assertThat(HttpUtils.isKeepAlive(req)).isTrue();

    when(req.version()).thenReturn(HttpVersion.HTTP_1_0);
    assertThat(HttpUtils.isKeepAlive(req)).isFalse();
}
项目:incubator-servicecomb-java-chassis    文件:TestClientPool.java   
@Test
public void testHttpClientPool() {
  new MockUp<ServiceRegistryConfig>() {
    @Mock
    public HttpVersion getHttpVersion() {
      return HttpVersion.HTTP_2;
    }

    @Mock
    public boolean isSsl() {
      return true;
    }
  };
  HttpClientPool.INSTANCE.create();
}
项目:incubator-servicecomb-java-chassis    文件:TestClientPool.java   
@Test
public void testWebsocketClientPool() {
  new MockUp<ServiceRegistryConfig>() {
    @Mock
    public HttpVersion getHttpVersion() {
      return HttpVersion.HTTP_2;
    }

    @Mock
    public boolean isSsl() {
      return true;
    }
  };
  WebsocketClientPool.INSTANCE.create();
}
项目:incubator-servicecomb-java-chassis    文件:VersionOrProtocolElement.java   
private String getStringVersion(HttpVersion version) {
  switch (version) {
    case HTTP_2:
      return "HTTP/2.0";
    case HTTP_1_0:
      return "HTTP/1.0";
    case HTTP_1_1:
      return "HTTP/1.1";
    default:
      return EMPTY_RESULT;
  }
}
项目:nubes    文件:TypedParamInjectorRegistry.java   
@SuppressWarnings({"unchecked", "rawtypes"})
public TypedParamInjectorRegistry(Config config) {
  map = new HashMap<>();
  registerInjector(Vertx.class, new VertxParamInjector());
  registerInjector(Session.class, new SessionParamInjector());
  registerInjector(RoutingContext.class, new RoutingContextParamInjector());
  registerInjector(Payload.class, new PayloadParamInjector());
  registerInjector(PaginationContext.class, new PaginationContextParamInjector());
  registerInjector(EventBus.class, new EventBusParamInjector());
  registerInjector(ResourceBundle.class, new ResourceBundleParamInjector(config));
  registerInjector(HttpServerRequest.class, new RequestParamInjector());
  registerInjector(HttpServerResponse.class, new ResponseParamInjector());
  registerInjector(SocketAddress.class, new SocketAddressParamInjector());
  registerInjector(HttpVersion.class, new HttpVersionParamInjector());
}
项目:vertx-web    文件:XhrTransport.java   
public void sendFrame(String body) {
  if (log.isTraceEnabled()) log.trace("XHR sending frame");
  if (!headersWritten) {
    HttpServerResponse resp = rc.response();
    resp.putHeader("Content-Type", "application/javascript; charset=UTF-8");
    setJSESSIONID(options, rc);
    setCORS(rc);
    if (rc.request().version() != HttpVersion.HTTP_1_0) {
      resp.setChunked(true);
    } else {
      resp.putHeader("Content-Length", "0");
    }
    headersWritten = true;
  }
}
项目:vertx-web    文件:StaticHandlerTest.java   
@Test
public void testNoHttp2Push() throws Exception {
  stat.setWebRoot("webroot/somedir3");
  router.route().handler(stat);
  HttpServer http2Server = vertx.createHttpServer(new HttpServerOptions()
    .setUseAlpn(true)
    .setSsl(true)
    .setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("tls/server-key.pem").setCertPath("tls/server-cert.pem")));
  http2Server.requestHandler(router::accept).listen(8443);

  HttpClientOptions options = new HttpClientOptions()
    .setSsl(true)
    .setUseAlpn(true)
    .setProtocolVersion(HttpVersion.HTTP_2)
    .setPemTrustOptions(new PemTrustOptions().addCertPath("tls/server-cert.pem"));
  HttpClient client = vertx.createHttpClient(options);
  HttpClientRequest request = client.get(8443, "localhost", "/testLinkPreload.html", resp -> {
    assertEquals(200, resp.statusCode());
    assertEquals(HttpVersion.HTTP_2, resp.version());
    resp.bodyHandler(this::assertNotNull);
    testComplete();
  });
  request.pushHandler(pushedReq -> pushedReq.handler(pushedResp -> {
    fail();
  }));
  request.end();
  await();
}
项目:vertx-web    文件:StaticHandlerTest.java   
@Test
public void testHttp2Push() throws Exception {
  List<Http2PushMapping> mappings = new ArrayList<>();
  mappings.add(new Http2PushMapping("style.css", "style", false));
  mappings.add(new Http2PushMapping("coin.png", "image", false));
  stat.setHttp2PushMapping(mappings)
      .setWebRoot("webroot/somedir3");
  router.route().handler(stat);
  HttpServer http2Server = vertx.createHttpServer(new HttpServerOptions()
      .setUseAlpn(true)
      .setSsl(true)
      .setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("tls/server-key.pem").setCertPath("tls/server-cert.pem")));
  http2Server.requestHandler(router::accept).listen(8443);

  HttpClientOptions options = new HttpClientOptions()
    .setSsl(true)
    .setUseAlpn(true)
    .setProtocolVersion(HttpVersion.HTTP_2)
    .setPemTrustOptions(new PemTrustOptions().addCertPath("tls/server-cert.pem"));
  HttpClient client = vertx.createHttpClient(options);
  HttpClientRequest request = client.get(8443, "localhost", "/testLinkPreload.html", resp -> {
    assertEquals(200, resp.statusCode());
    assertEquals(HttpVersion.HTTP_2, resp.version());
    resp.bodyHandler(this::assertNotNull);
  });
  CountDownLatch latch = new CountDownLatch(2);
  request.pushHandler(pushedReq -> pushedReq.handler(pushedResp -> {
    assertNotNull(pushedResp);
    pushedResp.bodyHandler(this::assertNotNull);
    latch.countDown();
  }));
  request.end();
  latch.await();
}
项目:wisdom    文件:HttpUtils.java   
/**
 * Checks whether the given request should be closed or not once completed.
 *
 * @param request the request
 * @return {@code true} if the connection is marked as {@literal keep-alive}, and so must not be closed. {@code
 * false} otherwise. Notice that if not set in the request, the default value depends on the HTTP version.
 */
public static boolean isKeepAlive(HttpServerRequest request) {
    String connection = request.headers().get(HeaderNames.CONNECTION);
    if (connection != null && connection.equalsIgnoreCase(CLOSE)) {
        return false;
    }
    if (request.version() == HttpVersion.HTTP_1_1) {
        return !CLOSE.equalsIgnoreCase(connection);
    } else {
        return KEEP_ALIVE.equalsIgnoreCase(connection);
    }
}
项目:apiman    文件:HttpApiFactory.java   
public static void buildResponse(HttpServerResponse httpServerResponse, ApiResponse amanResponse, HttpVersion httpVersion) {
    amanResponse.getHeaders().forEach(e -> {
        if (httpVersion == HttpVersion.HTTP_1_0 || httpVersion == HttpVersion.HTTP_1_1 || !e.getKey().equals("Connection")) {
            httpServerResponse.headers().add(e.getKey(), e.getValue());
        }
    });
    httpServerResponse.setStatusCode(amanResponse.getCode());
    httpServerResponse.setStatusMessage(amanResponse.getMessage() == null ? "" : amanResponse.getMessage());
}
项目:incubator-servicecomb-java-chassis    文件:ServiceRegistryConfig.java   
public HttpVersion getHttpVersion() {
  DynamicStringProperty property =
      DynamicPropertyFactory.getInstance()
          .getStringProperty("cse.service.registry.client.httpVersion", "HTTP_1_1");
  return HttpVersion.valueOf(property.get());
}
项目:vertx-aws-lambda    文件:HttpServerRequestImpl.java   
@Override
public HttpVersion version() {
    return HttpVersion.HTTP_1_1;
}
项目:vertx-aws-lambda    文件:HttpServerRequestImplTest.java   
@Test
public void testVersion(TestContext context) {
    context.assertEquals(HttpVersion.HTTP_1_1, request.version());
}
项目:domino    文件:ImmutableHttpServerOptions.java   
@Override
public List<HttpVersion> getAlpnVersions() {
    return options.getAlpnVersions();
}
项目:vertx-futures    文件:HttpClientRequestWithFutureResponse.java   
public HttpClientRequestWithFutureResponse sendHead(Handler<HttpVersion> completionHandler) {
  request.sendHead(completionHandler);
  return this;
}
项目:vertx-pairtree    文件:S3ClientRequest.java   
@Override
public HttpClientRequest sendHead(final Handler<HttpVersion> aHandler) {
    return myRequest.sendHead(aHandler);
}
项目:vertx-swagger    文件:InterceptableRoutingContextImplTest.java   
@Override
public HttpVersion version() {
    // TODO Auto-generated method stub
    return null;
}
项目:sfs    文件:SfsRequest.java   
@Override
public HttpVersion version() {
    return httpServerRequest.version();
}
项目:vertx-utils    文件:HttpServerRequestWrapper.java   
@Override
public HttpVersion version() {
    return serverRequest.version();
}
项目:nubes    文件:HttpVersionParamInjector.java   
@Override
public HttpVersion resolve(RoutingContext context) {
  return context.request().version();
}
项目:nubes    文件:MethodParamInjectionController.java   
@GET("/httpVersion")
@ContentType("application/json")
public JsonObject getNetSocket(HttpVersion version) {
    return new JsonObject()
            .put("version", version.toString());
}
项目:vertx-web    文件:WebClientOptions.java   
@Override
public WebClientOptions setProtocolVersion(HttpVersion protocolVersion) {
  return (WebClientOptions) super.setProtocolVersion(protocolVersion);
}
项目:vertx-web    文件:WebClientOptions.java   
@Override
public WebClientOptions setAlpnVersions(List<HttpVersion> alpnVersions) {
  return (WebClientOptions) super.setAlpnVersions(alpnVersions);
}
项目:vertx-web    文件:HttpResponseImpl.java   
@Override
public HttpVersion version() {
  return resp.version();
}
项目:vertx-web    文件:InterceptorTest.java   
@Override
public HttpVersion version() {
  return HttpVersion.HTTP_1_1;
}
项目:vertx-web    文件:VirtualHostHandlerHttp2Test.java   
@Override
protected HttpClientOptions getHttpClientOptions() {
  return super.getHttpClientOptions().setProtocolVersion(HttpVersion.HTTP_2);
}
项目:vertx-codetrans    文件:ServerOptions.java   
public HttpVersion getProtocolVersion() {
  return protocolVersion;
}
项目:vertx-codetrans    文件:ServerOptions.java   
public ServerOptions setProtocolVersion(HttpVersion protocolVersion) {
  this.protocolVersion = protocolVersion;
  return this;
}
项目:vertx-codetrans    文件:DataObject.java   
@CodeTranslate
public void enumValueFromConstructor() throws Exception {
  ServerOptions obj = new ServerOptions().setProtocolVersion(HttpVersion.HTTP_2);
  DataObjectTest.o = obj;
}
项目:vertx-codetrans    文件:DataObject.java   
@CodeTranslate
public void enumValueFromIdentifier() throws Exception {
  ServerOptions obj = new ServerOptions();
  obj.setProtocolVersion(HttpVersion.HTTP_2);
  DataObjectTest.o = obj;
}
项目:apiman    文件:Router2ResteasyRequestAdapter.java   
@Override
public HttpVersion version() {
    return request.version();
}
项目:vertx-consul-client    文件:ConsulClientOptions.java   
/**
 * Set the protocol version.
 *
 * @param protocolVersion the protocol version
 * @return a reference to this, so the API can be used fluently
 */
@Override
public ConsulClientOptions setProtocolVersion(HttpVersion protocolVersion) {
  return (ConsulClientOptions) super.setProtocolVersion(protocolVersion);
}
项目:vertx-consul-client    文件:ConsulClientOptions.java   
/**
 * Set the list of protocol versions to provide to the server during the Application-Layer Protocol Negotiation.
 * When the list is empty, the client provides a best effort list according to {@link #setProtocolVersion}:
 *
 * <ul>
 *   <li>{@link HttpVersion#HTTP_2}: [ "h2", "http/1.1" ]</li>
 *   <li>otherwise: [{@link #getProtocolVersion()}]</li>
 * </ul>
 *
 * @param alpnVersions the versions
 * @return a reference to this, so the API can be used fluently
 */
@Override
public ConsulClientOptions setAlpnVersions(List<HttpVersion> alpnVersions) {
  return (ConsulClientOptions) super.setAlpnVersions(alpnVersions);
}
项目:vertx-web    文件:HttpResponse.java   
/**
 * @return the version of the response
 */
@CacheReturn
HttpVersion version();