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

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

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

HttpProxyHandler介绍

暂无

代码示例

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

  1. @Override
  2. public ProxyHandler createProxyHandler() {
  3. final HttpProxyHandler handler;
  4. // For reasons that are not immediately clear, HttpProxyHandler doesn't allow null usernames/passwords if
  5. // specified. If we want them to be null, we have to use the constructor that doesn't take a username/password
  6. // at all.
  7. if (this.username != null && this.password != null) {
  8. handler = new HttpProxyHandler(this.proxyAddress, this.username, this.password);
  9. } else {
  10. handler = new HttpProxyHandler(this.proxyAddress);
  11. }
  12. return handler;
  13. }
  14. }

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

  1. @Override
  2. protected Object newInitialMessage(ChannelHandlerContext ctx) throws Exception {
  3. InetSocketAddress raddr = destinationAddress();
  4. String hostString = HttpUtil.formatHostnameForHttp(raddr);
  5. int port = raddr.getPort();
  6. String url = hostString + ":" + port;
  7. String hostHeader = (ignoreDefaultPortsInConnectHostHeader && (port == 80 || port == 443)) ?
  8. hostString :
  9. url;
  10. FullHttpRequest req = new DefaultFullHttpRequest(
  11. HttpVersion.HTTP_1_1, HttpMethod.CONNECT,
  12. url,
  13. Unpooled.EMPTY_BUFFER, false);
  14. req.headers().set(HttpHeaderNames.HOST, hostHeader);
  15. if (authorization != null) {
  16. req.headers().set(HttpHeaderNames.PROXY_AUTHORIZATION, authorization);
  17. }
  18. if (headers != null) {
  19. req.headers().add(headers);
  20. }
  21. return req;
  22. }

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

  1. @Override
  2. protected boolean handleResponse(ChannelHandlerContext ctx, Object response) throws Exception {
  3. if (response instanceof HttpResponse) {
  4. if (status != null) {
  5. throw new ProxyConnectException(exceptionMessage("too many responses"));
  6. }
  7. status = ((HttpResponse) response).status();
  8. }
  9. boolean finished = response instanceof LastHttpContent;
  10. if (finished) {
  11. if (status == null) {
  12. throw new ProxyConnectException(exceptionMessage("missing response"));
  13. }
  14. if (status.code() != 200) {
  15. throw new ProxyConnectException(exceptionMessage("status: " + status));
  16. }
  17. }
  18. return finished;
  19. }
  20. }

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

  1. switch (proxyType) {
  2. case HTTP:
  3. pipeline.addLast(HANDLER_HTTP_PROXY, new HttpProxyHandler(proxyAddress, username, password));
  4. break;
  5. case SOCKS:
  6. switch (proxyType) {
  7. case HTTP:
  8. pipeline.addLast(HANDLER_HTTP_PROXY, new HttpProxyHandler(proxyAddress));
  9. break;
  10. case SOCKS:

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

  1. @Override
  2. protected boolean handleResponse(ChannelHandlerContext ctx, Object response) throws Exception {
  3. if (response instanceof HttpResponse) {
  4. if (status != null) {
  5. throw new ProxyConnectException(exceptionMessage("too many responses"));
  6. }
  7. status = ((HttpResponse) response).status();
  8. }
  9. boolean finished = response instanceof LastHttpContent;
  10. if (finished) {
  11. if (status == null) {
  12. throw new ProxyConnectException(exceptionMessage("missing response"));
  13. }
  14. if (status.code() != 200) {
  15. throw new ProxyConnectException(exceptionMessage("status: " + status));
  16. }
  17. }
  18. return finished;
  19. }
  20. }

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

  1. @Override
  2. protected Object newInitialMessage(ChannelHandlerContext ctx) throws Exception {
  3. InetSocketAddress raddr = destinationAddress();
  4. String hostString = HttpUtil.formatHostnameForHttp(raddr);
  5. int port = raddr.getPort();
  6. String url = hostString + ":" + port;
  7. String hostHeader = (ignoreDefaultPortsInConnectHostHeader && (port == 80 || port == 443)) ?
  8. hostString :
  9. url;
  10. FullHttpRequest req = new DefaultFullHttpRequest(
  11. HttpVersion.HTTP_1_1, HttpMethod.CONNECT,
  12. url,
  13. Unpooled.EMPTY_BUFFER, false);
  14. req.headers().set(HttpHeaderNames.HOST, hostHeader);
  15. if (authorization != null) {
  16. req.headers().set(HttpHeaderNames.PROXY_AUTHORIZATION, authorization);
  17. }
  18. if (headers != null) {
  19. req.headers().add(headers);
  20. }
  21. return req;
  22. }

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

  1. @Override
  2. protected void initChannel(SocketChannel ch) throws Exception {
  3. ChannelPipeline p = ch.pipeline();
  4. // Enable HTTPS if necessary.
  5. if ("https".equals(requestUri.getScheme())) {
  6. // making client authentication optional for now; it could be extracted to configurable property
  7. JdkSslContext jdkSslContext = new JdkSslContext(client.getSslContext(), true, ClientAuth.NONE);
  8. p.addLast(jdkSslContext.newHandler(ch.alloc()));
  9. }
  10. // http proxy
  11. Configuration config = jerseyRequest.getConfiguration();
  12. final Object proxyUri = config.getProperties().get(ClientProperties.PROXY_URI);
  13. if (proxyUri != null) {
  14. final URI u = getProxyUri(proxyUri);
  15. final String userName = ClientProperties.getValue(
  16. config.getProperties(), ClientProperties.PROXY_USERNAME, String.class);
  17. final String password = ClientProperties.getValue(
  18. config.getProperties(), ClientProperties.PROXY_PASSWORD, String.class);
  19. p.addLast(new HttpProxyHandler(new InetSocketAddress(u.getHost(),
  20. u.getPort() == -1 ? 8080 : u.getPort()),
  21. userName, password));
  22. }
  23. p.addLast(new HttpClientCodec());
  24. p.addLast(new ChunkedWriteHandler());
  25. p.addLast(new HttpContentDecompressor());
  26. p.addLast(new JerseyClientHandler(NettyConnector.this, jerseyRequest, jerseyCallback, settableFuture));
  27. }
  28. });

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

  1. @Override
  2. protected boolean handleResponse(ChannelHandlerContext ctx, Object response) throws Exception {
  3. if (response instanceof HttpResponse) {
  4. if (status != null) {
  5. throw new ProxyConnectException(exceptionMessage("too many responses"));
  6. }
  7. status = ((HttpResponse) response).status();
  8. }
  9. boolean finished = response instanceof LastHttpContent;
  10. if (finished) {
  11. if (status == null) {
  12. throw new ProxyConnectException(exceptionMessage("missing response"));
  13. }
  14. if (status.code() != 200) {
  15. throw new ProxyConnectException(exceptionMessage("status: " + status));
  16. }
  17. }
  18. return finished;
  19. }
  20. }

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

  1. @Override
  2. protected Object newInitialMessage(ChannelHandlerContext ctx) throws Exception {
  3. InetSocketAddress raddr = destinationAddress();
  4. String hostString = HttpUtil.formatHostnameForHttp(raddr);
  5. int port = raddr.getPort();
  6. String url = hostString + ":" + port;
  7. String hostHeader = (ignoreDefaultPortsInConnectHostHeader && (port == 80 || port == 443)) ?
  8. hostString :
  9. url;
  10. FullHttpRequest req = new DefaultFullHttpRequest(
  11. HttpVersion.HTTP_1_1, HttpMethod.CONNECT,
  12. url,
  13. Unpooled.EMPTY_BUFFER, false);
  14. req.headers().set(HttpHeaderNames.HOST, hostHeader);
  15. if (authorization != null) {
  16. req.headers().set(HttpHeaderNames.PROXY_AUTHORIZATION, authorization);
  17. }
  18. if (headers != null) {
  19. req.headers().add(headers);
  20. }
  21. return req;
  22. }

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

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

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

  1. case HTTP:
  2. proxy = proxyUsername != null && proxyPassword != null
  3. ? new HttpProxyHandler(proxyAddr, proxyUsername, proxyPassword) : new HttpProxyHandler(proxyAddr);
  4. break;
  5. case SOCKS5:

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

  1. private @Nullable HttpProxyHandler newHttpProxyHandlerIfNeeded(HttpProxyConfig httpProxyConfig,
  2. @Nullable String passwordOverride) throws Exception {
  3. String proxyHost = httpProxyConfig.host();
  4. if (proxyHost.isEmpty()) {
  5. return null;
  6. }
  7. int proxyPort = MoreObjects.firstNonNull(httpProxyConfig.port(), 80);
  8. SocketAddress proxyAddress = new InetSocketAddress(proxyHost, proxyPort);
  9. String username = httpProxyConfig.username();
  10. if (username.isEmpty()) {
  11. return new HttpProxyHandler(proxyAddress);
  12. } else {
  13. String password = getPassword(httpProxyConfig, passwordOverride);
  14. return new HttpProxyHandler(proxyAddress, username, password);
  15. }
  16. }

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

  1. case HTTP:
  2. proxy = proxyUsername != null && proxyPassword != null
  3. ? new HttpProxyHandler(proxyAddr, proxyUsername, proxyPassword) : new HttpProxyHandler(proxyAddr);
  4. break;
  5. case SOCKS5:

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

  1. @Override
  2. public ProxyHandler createProxyHandler() {
  3. final HttpProxyHandler handler;
  4. // For reasons that are not immediately clear, HttpProxyHandler doesn't allow null usernames/passwords if
  5. // specified. If we want them to be null, we have to use the constructor that doesn't take a username/password
  6. // at all.
  7. if (this.username != null && this.password != null) {
  8. handler = new HttpProxyHandler(this.proxyAddress, this.username, this.password);
  9. } else {
  10. handler = new HttpProxyHandler(this.proxyAddress);
  11. }
  12. return handler;
  13. }
  14. }

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

  1. @Override
  2. public ProxyHandler createProxyHandler() {
  3. final HttpProxyHandler handler;
  4. // For reasons that are not immediately clear, HttpProxyHandler doesn't allow null usernames/passwords if
  5. // specified. If we want them to be null, we have to use the constructor that doesn't take a username/password
  6. // at all.
  7. if (this.username != null && this.password != null) {
  8. handler = new HttpProxyHandler(this.proxyAddress, this.username, this.password);
  9. } else {
  10. handler = new HttpProxyHandler(this.proxyAddress);
  11. }
  12. return handler;
  13. }
  14. }

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

  1. /**
  2. * Return a new eventual {@link ProxyHandler}
  3. *
  4. * @return a new eventual {@link ProxyHandler}
  5. */
  6. public final ProxyHandler newProxyHandler() {
  7. InetSocketAddress proxyAddr = this.address.get();
  8. String username = this.username;
  9. String password = Objects.nonNull(username) && Objects.nonNull(this.password) ?
  10. this.password.apply(username) : null;
  11. switch (this.type) {
  12. case HTTP:
  13. return Objects.nonNull(username) && Objects.nonNull(password) ?
  14. new HttpProxyHandler(proxyAddr, username, password) :
  15. new HttpProxyHandler(proxyAddr);
  16. case SOCKS4:
  17. return Objects.nonNull(username) ? new Socks4ProxyHandler(proxyAddr, username) :
  18. new Socks4ProxyHandler(proxyAddr);
  19. case SOCKS5:
  20. return Objects.nonNull(username) && Objects.nonNull(password) ?
  21. new Socks5ProxyHandler(proxyAddr, username, password) :
  22. new Socks5ProxyHandler(proxyAddr);
  23. }
  24. throw new IllegalArgumentException("Proxy type unsupported : " + this.type);
  25. }

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

  1. /**
  2. * Return a new eventual {@link ProxyHandler}
  3. *
  4. * @return a new eventual {@link ProxyHandler}
  5. */
  6. public final ProxyHandler newProxyHandler() {
  7. InetSocketAddress proxyAddr = this.address.get();
  8. String username = this.username;
  9. String password = Objects.nonNull(username) && Objects.nonNull(this.password) ?
  10. this.password.apply(username) : null;
  11. switch (this.type) {
  12. case HTTP:
  13. return Objects.nonNull(username) && Objects.nonNull(password) ?
  14. new HttpProxyHandler(proxyAddr, username, password) :
  15. new HttpProxyHandler(proxyAddr);
  16. case SOCKS4:
  17. return Objects.nonNull(username) ? new Socks4ProxyHandler(proxyAddr, username) :
  18. new Socks4ProxyHandler(proxyAddr);
  19. case SOCKS5:
  20. return Objects.nonNull(username) && Objects.nonNull(password) ?
  21. new Socks5ProxyHandler(proxyAddr, username, password) :
  22. new Socks5ProxyHandler(proxyAddr);
  23. }
  24. throw new IllegalArgumentException("Proxy type unsupported : " + this.type);
  25. }

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

  1. /**
  2. * Return a new eventual {@link ProxyHandler}
  3. *
  4. * @return a new eventual {@link ProxyHandler}
  5. */
  6. public final ProxyHandler newProxyHandler() {
  7. InetSocketAddress proxyAddr = this.address.get();
  8. String username = this.username;
  9. String password = Objects.nonNull(username) && Objects.nonNull(this.password) ?
  10. this.password.apply(username) : null;
  11. switch (this.type) {
  12. case HTTP:
  13. return Objects.nonNull(username) && Objects.nonNull(password) ?
  14. new HttpProxyHandler(proxyAddr, username, password) :
  15. new HttpProxyHandler(proxyAddr);
  16. case SOCKS4:
  17. return Objects.nonNull(username) ? new Socks4ProxyHandler(proxyAddr, username) :
  18. new Socks4ProxyHandler(proxyAddr);
  19. case SOCKS5:
  20. return Objects.nonNull(username) && Objects.nonNull(password) ?
  21. new Socks5ProxyHandler(proxyAddr, username, password) :
  22. new Socks5ProxyHandler(proxyAddr);
  23. }
  24. throw new IllegalArgumentException("Proxy type unsupported : " + this.type);
  25. }

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

  1. @Value.Derived
  2. Optional<ChannelHandler> getHttpProxyHandler() {
  3. if (StringUtils.hasText(getHost())) {
  4. InetSocketAddress proxyAddress = new InetSocketAddress(getHost(), Optional.ofNullable(getPort()).orElse(8080));
  5. HttpProxyHandler httpProxyHandler;
  6. if (getUsername() != null) {
  7. httpProxyHandler = new HttpProxyHandler(proxyAddress, getUsername(), getPassword());
  8. } else {
  9. httpProxyHandler = new HttpProxyHandler(proxyAddress);
  10. }
  11. return Optional.of(httpProxyHandler);
  12. }
  13. return Optional.empty();
  14. }

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

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

相关文章