io.netty.handler.proxy.HttpProxyHandler类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(486)

本文整理了Java中io.netty.handler.proxy.HttpProxyHandler类的一些代码示例,展示了HttpProxyHandler类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpProxyHandler类的具体详情如下:
包路径:io.netty.handler.proxy.HttpProxyHandler
类名称:HttpProxyHandler

HttpProxyHandler介绍

暂无

代码示例

代码示例来源:origin: relayrides/pushy

@Override
  public ProxyHandler createProxyHandler() {
    final HttpProxyHandler handler;

    // For reasons that are not immediately clear, HttpProxyHandler doesn't allow null usernames/passwords if
    // specified. If we want them to be null, we have to use the constructor that doesn't take a username/password
    // at all.
    if (this.username != null && this.password != null) {
      handler = new HttpProxyHandler(this.proxyAddress, this.username, this.password);
    } else {
      handler = new HttpProxyHandler(this.proxyAddress);
    }

    return handler;
  }
}

代码示例来源:origin: wildfly/wildfly

@Override
protected Object newInitialMessage(ChannelHandlerContext ctx) throws Exception {
  InetSocketAddress raddr = destinationAddress();
  String hostString = HttpUtil.formatHostnameForHttp(raddr);
  int port = raddr.getPort();
  String url = hostString + ":" + port;
  String hostHeader = (ignoreDefaultPortsInConnectHostHeader && (port == 80 || port == 443)) ?
      hostString :
      url;
  FullHttpRequest req = new DefaultFullHttpRequest(
      HttpVersion.HTTP_1_1, HttpMethod.CONNECT,
      url,
      Unpooled.EMPTY_BUFFER, false);
  req.headers().set(HttpHeaderNames.HOST, hostHeader);
  if (authorization != null) {
    req.headers().set(HttpHeaderNames.PROXY_AUTHORIZATION, authorization);
  }
  if (headers != null) {
    req.headers().add(headers);
  }
  return req;
}

代码示例来源:origin: wildfly/wildfly

@Override
  protected boolean handleResponse(ChannelHandlerContext ctx, Object response) throws Exception {
    if (response instanceof HttpResponse) {
      if (status != null) {
        throw new ProxyConnectException(exceptionMessage("too many responses"));
      }
      status = ((HttpResponse) response).status();
    }

    boolean finished = response instanceof LastHttpContent;
    if (finished) {
      if (status == null) {
        throw new ProxyConnectException(exceptionMessage("missing response"));
      }
      if (status.code() != 200) {
        throw new ProxyConnectException(exceptionMessage("status: " + status));
      }
    }

    return finished;
  }
}

代码示例来源:origin: micronaut-projects/micronaut-core

switch (proxyType) {
  case HTTP:
    pipeline.addLast(HANDLER_HTTP_PROXY, new HttpProxyHandler(proxyAddress, username, password));
    break;
  case SOCKS:
switch (proxyType) {
  case HTTP:
    pipeline.addLast(HANDLER_HTTP_PROXY, new HttpProxyHandler(proxyAddress));
    break;
  case SOCKS:

代码示例来源:origin: io.netty/netty-handler-proxy

@Override
  protected boolean handleResponse(ChannelHandlerContext ctx, Object response) throws Exception {
    if (response instanceof HttpResponse) {
      if (status != null) {
        throw new ProxyConnectException(exceptionMessage("too many responses"));
      }
      status = ((HttpResponse) response).status();
    }

    boolean finished = response instanceof LastHttpContent;
    if (finished) {
      if (status == null) {
        throw new ProxyConnectException(exceptionMessage("missing response"));
      }
      if (status.code() != 200) {
        throw new ProxyConnectException(exceptionMessage("status: " + status));
      }
    }

    return finished;
  }
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

@Override
protected Object newInitialMessage(ChannelHandlerContext ctx) throws Exception {
  InetSocketAddress raddr = destinationAddress();
  String hostString = HttpUtil.formatHostnameForHttp(raddr);
  int port = raddr.getPort();
  String url = hostString + ":" + port;
  String hostHeader = (ignoreDefaultPortsInConnectHostHeader && (port == 80 || port == 443)) ?
      hostString :
      url;
  FullHttpRequest req = new DefaultFullHttpRequest(
      HttpVersion.HTTP_1_1, HttpMethod.CONNECT,
      url,
      Unpooled.EMPTY_BUFFER, false);
  req.headers().set(HttpHeaderNames.HOST, hostHeader);
  if (authorization != null) {
    req.headers().set(HttpHeaderNames.PROXY_AUTHORIZATION, authorization);
  }
  if (headers != null) {
    req.headers().add(headers);
  }
  return req;
}

代码示例来源:origin: jersey/jersey

@Override
  protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();
    // Enable HTTPS if necessary.
    if ("https".equals(requestUri.getScheme())) {
      // making client authentication optional for now; it could be extracted to configurable property
      JdkSslContext jdkSslContext = new JdkSslContext(client.getSslContext(), true, ClientAuth.NONE);
      p.addLast(jdkSslContext.newHandler(ch.alloc()));
    }
    // http proxy
    Configuration config = jerseyRequest.getConfiguration();
    final Object proxyUri = config.getProperties().get(ClientProperties.PROXY_URI);
    if (proxyUri != null) {
      final URI u = getProxyUri(proxyUri);
      final String userName = ClientProperties.getValue(
          config.getProperties(), ClientProperties.PROXY_USERNAME, String.class);
      final String password = ClientProperties.getValue(
          config.getProperties(), ClientProperties.PROXY_PASSWORD, String.class);
      p.addLast(new HttpProxyHandler(new InetSocketAddress(u.getHost(),
                                u.getPort() == -1 ? 8080 : u.getPort()),
                     userName, password));
    }
    p.addLast(new HttpClientCodec());
    p.addLast(new ChunkedWriteHandler());
    p.addLast(new HttpContentDecompressor());
    p.addLast(new JerseyClientHandler(NettyConnector.this, jerseyRequest, jerseyCallback, settableFuture));
  }
});

代码示例来源:origin: org.jboss.eap/wildfly-client-all

@Override
  protected boolean handleResponse(ChannelHandlerContext ctx, Object response) throws Exception {
    if (response instanceof HttpResponse) {
      if (status != null) {
        throw new ProxyConnectException(exceptionMessage("too many responses"));
      }
      status = ((HttpResponse) response).status();
    }

    boolean finished = response instanceof LastHttpContent;
    if (finished) {
      if (status == null) {
        throw new ProxyConnectException(exceptionMessage("missing response"));
      }
      if (status.code() != 200) {
        throw new ProxyConnectException(exceptionMessage("status: " + status));
      }
    }

    return finished;
  }
}

代码示例来源:origin: io.netty/netty-handler-proxy

@Override
protected Object newInitialMessage(ChannelHandlerContext ctx) throws Exception {
  InetSocketAddress raddr = destinationAddress();
  String hostString = HttpUtil.formatHostnameForHttp(raddr);
  int port = raddr.getPort();
  String url = hostString + ":" + port;
  String hostHeader = (ignoreDefaultPortsInConnectHostHeader && (port == 80 || port == 443)) ?
      hostString :
      url;
  FullHttpRequest req = new DefaultFullHttpRequest(
      HttpVersion.HTTP_1_1, HttpMethod.CONNECT,
      url,
      Unpooled.EMPTY_BUFFER, false);
  req.headers().set(HttpHeaderNames.HOST, hostHeader);
  if (authorization != null) {
    req.headers().set(HttpHeaderNames.PROXY_AUTHORIZATION, authorization);
  }
  if (headers != null) {
    req.headers().add(headers);
  }
  return req;
}

代码示例来源:origin: jamesdbloom/mockserver

pipeline.addLast(new HttpProxyHandler(proxyConfiguration.getProxyAddress()));
} else if (proxyConfiguration.getType() == ProxyConfiguration.Type.SOCKS5) {
  pipeline.addLast(new Socks5ProxyHandler(proxyConfiguration.getProxyAddress()));

代码示例来源:origin: eclipse-vertx/vert.x

case HTTP:
 proxy = proxyUsername != null && proxyPassword != null
  ? new HttpProxyHandler(proxyAddr, proxyUsername, proxyPassword) : new HttpProxyHandler(proxyAddr);
 break;
case SOCKS5:

代码示例来源:origin: glowroot/glowroot

private @Nullable HttpProxyHandler newHttpProxyHandlerIfNeeded(HttpProxyConfig httpProxyConfig,
    @Nullable String passwordOverride) throws Exception {
  String proxyHost = httpProxyConfig.host();
  if (proxyHost.isEmpty()) {
    return null;
  }
  int proxyPort = MoreObjects.firstNonNull(httpProxyConfig.port(), 80);
  SocketAddress proxyAddress = new InetSocketAddress(proxyHost, proxyPort);
  String username = httpProxyConfig.username();
  if (username.isEmpty()) {
    return new HttpProxyHandler(proxyAddress);
  } else {
    String password = getPassword(httpProxyConfig, passwordOverride);
    return new HttpProxyHandler(proxyAddress, username, password);
  }
}

代码示例来源:origin: io.vertx/vertx-core

case HTTP:
 proxy = proxyUsername != null && proxyPassword != null
  ? new HttpProxyHandler(proxyAddr, proxyUsername, proxyPassword) : new HttpProxyHandler(proxyAddr);
 break;
case SOCKS5:

代码示例来源:origin: com.relayrides/pushy

@Override
  public ProxyHandler createProxyHandler() {
    final HttpProxyHandler handler;

    // For reasons that are not immediately clear, HttpProxyHandler doesn't allow null usernames/passwords if
    // specified. If we want them to be null, we have to use the constructor that doesn't take a username/password
    // at all.
    if (this.username != null && this.password != null) {
      handler = new HttpProxyHandler(this.proxyAddress, this.username, this.password);
    } else {
      handler = new HttpProxyHandler(this.proxyAddress);
    }

    return handler;
  }
}

代码示例来源:origin: com.turo/pushy

@Override
  public ProxyHandler createProxyHandler() {
    final HttpProxyHandler handler;

    // For reasons that are not immediately clear, HttpProxyHandler doesn't allow null usernames/passwords if
    // specified. If we want them to be null, we have to use the constructor that doesn't take a username/password
    // at all.
    if (this.username != null && this.password != null) {
      handler = new HttpProxyHandler(this.proxyAddress, this.username, this.password);
    } else {
      handler = new HttpProxyHandler(this.proxyAddress);
    }

    return handler;
  }
}

代码示例来源:origin: io.projectreactor.netty/reactor-netty

/**
 * Return a new eventual {@link ProxyHandler}
 *
 * @return a new eventual {@link ProxyHandler}
 */
public final ProxyHandler newProxyHandler() {
  InetSocketAddress proxyAddr = this.address.get();
  String username = this.username;
  String password = Objects.nonNull(username) && Objects.nonNull(this.password) ?
      this.password.apply(username) : null;
  switch (this.type) {
    case HTTP:
      return Objects.nonNull(username) && Objects.nonNull(password) ?
          new HttpProxyHandler(proxyAddr, username, password) :
          new HttpProxyHandler(proxyAddr);
    case SOCKS4:
      return Objects.nonNull(username) ? new Socks4ProxyHandler(proxyAddr, username) :
          new Socks4ProxyHandler(proxyAddr);
    case SOCKS5:
      return Objects.nonNull(username) && Objects.nonNull(password) ?
          new Socks5ProxyHandler(proxyAddr, username, password) :
          new Socks5ProxyHandler(proxyAddr);
  }
  throw new IllegalArgumentException("Proxy type unsupported : " + this.type);
}

代码示例来源:origin: reactor/reactor-netty

/**
 * Return a new eventual {@link ProxyHandler}
 *
 * @return a new eventual {@link ProxyHandler}
 */
public final ProxyHandler newProxyHandler() {
  InetSocketAddress proxyAddr = this.address.get();
  String username = this.username;
  String password = Objects.nonNull(username) && Objects.nonNull(this.password) ?
      this.password.apply(username) : null;
  switch (this.type) {
    case HTTP:
      return Objects.nonNull(username) && Objects.nonNull(password) ?
          new HttpProxyHandler(proxyAddr, username, password) :
          new HttpProxyHandler(proxyAddr);
    case SOCKS4:
      return Objects.nonNull(username) ? new Socks4ProxyHandler(proxyAddr, username) :
          new Socks4ProxyHandler(proxyAddr);
    case SOCKS5:
      return Objects.nonNull(username) && Objects.nonNull(password) ?
          new Socks5ProxyHandler(proxyAddr, username, password) :
          new Socks5ProxyHandler(proxyAddr);
  }
  throw new IllegalArgumentException("Proxy type unsupported : " + this.type);
}

代码示例来源:origin: io.projectreactor.ipc/reactor-netty

/**
 * Return a new eventual {@link ProxyHandler}
 *
 * @return a new eventual {@link ProxyHandler}
 */
public final ProxyHandler newProxyHandler() {
  InetSocketAddress proxyAddr = this.address.get();
  String username = this.username;
  String password = Objects.nonNull(username) && Objects.nonNull(this.password) ?
      this.password.apply(username) : null;
  switch (this.type) {
    case HTTP:
      return Objects.nonNull(username) && Objects.nonNull(password) ?
          new HttpProxyHandler(proxyAddr, username, password) :
          new HttpProxyHandler(proxyAddr);
    case SOCKS4:
      return Objects.nonNull(username) ? new Socks4ProxyHandler(proxyAddr, username) :
          new Socks4ProxyHandler(proxyAddr);
    case SOCKS5:
      return Objects.nonNull(username) && Objects.nonNull(password) ?
          new Socks5ProxyHandler(proxyAddr, username, password) :
          new Socks5ProxyHandler(proxyAddr);
  }
  throw new IllegalArgumentException("Proxy type unsupported : " + this.type);
}

代码示例来源:origin: org.cloudfoundry/cloudfoundry-client-spring

@Value.Derived
Optional<ChannelHandler> getHttpProxyHandler() {
  if (StringUtils.hasText(getHost())) {
    InetSocketAddress proxyAddress = new InetSocketAddress(getHost(), Optional.ofNullable(getPort()).orElse(8080));
    HttpProxyHandler httpProxyHandler;
    if (getUsername() != null) {
      httpProxyHandler = new HttpProxyHandler(proxyAddress, getUsername(), getPassword());
    } else {
      httpProxyHandler = new HttpProxyHandler(proxyAddress);
    }
    return Optional.of(httpProxyHandler);
  }
  return Optional.empty();
}

代码示例来源:origin: Lihuanghe/SMSGate

pipeline.addLast(new HttpProxyHandler(new InetSocketAddress(host,port)));
}else{
  pipeline.addLast(new HttpProxyHandler(new InetSocketAddress(host,port),username,pass));

相关文章