io.netty.handler.codec.socksx.v4.DefaultSocks4CommandResponse Java Examples
The following examples show how to use
io.netty.handler.codec.socksx.v4.DefaultSocks4CommandResponse.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SocksProxyHandler.java From nitmproxy with MIT License | 6 votes |
private void onSocksSuccess(ChannelHandlerContext ctx, Socks4CommandRequest request) { Address serverAddr = new Address(request.dstAddr(), request.dstPort()); createServerChannel(ctx, serverAddr).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { ConnectionInfo newConnectionInfo = new ConnectionInfo( connectionInfo.getClientAddr(), serverAddr); ctx.writeAndFlush(new DefaultSocks4CommandResponse( Socks4CommandStatus.SUCCESS, request.dstAddr(), request.dstPort())); onServerConnected(ctx, newConnectionInfo, future.channel()); } else { ctx.channel().writeAndFlush(new DefaultSocks4CommandResponse( Socks4CommandStatus.REJECTED_OR_FAILED, request.dstAddr(), request.dstPort())); ctx.close(); } } }); }
Example #2
Source File: ProxyClientIntegrationTest.java From armeria with Apache License 2.0 | 6 votes |
@Test void testProxy_protocolUpgrade_notSharableExceptionNotThrown() throws Exception { DYNAMIC_HANDLER.setWriteCustomizer((ctx, msg, promise) -> { ctx.write(new DefaultSocks4CommandResponse(Socks4CommandStatus.REJECTED_OR_FAILED), promise); }); final ClientFactory clientFactory = ClientFactory.builder().proxyConfig( ProxyConfig.socks4(socksProxyServer.address())).build(); final WebClient webClient = WebClient.builder(SessionProtocol.HTTP, backendServer.httpEndpoint()) .factory(clientFactory) .decorator(LoggingClient.newDecorator()) .build(); final CompletableFuture<AggregatedHttpResponse> responseFuture = webClient.get(PROXY_PATH).aggregate(); assertThatThrownBy(responseFuture::join).isInstanceOf(CompletionException.class) .hasCauseInstanceOf(UnprocessedRequestException.class) .hasRootCauseInstanceOf(ProxyConnectException.class); clientFactory.close(); }
Example #3
Source File: ProxyClientIntegrationTest.java From armeria with Apache License 2.0 | 6 votes |
@Test void testProxy_responseFailure_throwsException() throws Exception { DYNAMIC_HANDLER.setWriteCustomizer((ctx, msg, promise) -> { ctx.write(new DefaultSocks4CommandResponse(Socks4CommandStatus.REJECTED_OR_FAILED), promise); }); final ClientFactory clientFactory = ClientFactory.builder().proxyConfig( ProxyConfig.socks4(socksProxyServer.address())).build(); final WebClient webClient = WebClient.builder(H1C, backendServer.httpEndpoint()) .factory(clientFactory) .decorator(LoggingClient.newDecorator()) .build(); final CompletableFuture<AggregatedHttpResponse> responseFuture = webClient.get(PROXY_PATH).aggregate(); assertThatThrownBy(responseFuture::join).isInstanceOf(CompletionException.class) .hasCauseInstanceOf(UnprocessedRequestException.class) .hasRootCauseInstanceOf(ProxyConnectException.class); clientFactory.close(); }