@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { final Object type = event.type(); if (type == ContinueEvent.class) { final ContinueEvent continueEvent = (ContinueEvent) event; continueEvent.getContext().payloadGenerator.continueConfirmed(ctx); } return ctx.getStopAction(); } // ----------------------------------------------------- Private Methods
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == SSLSwitchingEvent.class) { final SSLSwitchingEvent se = (SSLSwitchingEvent) event; final boolean isSecure = se.isSecure(); CONNECTION_IS_SECURE.set(se.getConnection(), isSecure); // if enabling security - create SSLEngine here, because default // Grizzly SSLFilter will use host/port info from the Connection, rather // than request URL. Specifically this doesn't work with CONNECT tunnels. if (isSecure && SSLUtils.getSSLEngine(ctx.getConnection()) == null) { // if SSLEngine is not yet set for the connection - initialize it final SSLEngine sslEngine = getClientSSLEngineConfigurator() .createSSLEngine(se.getHost(), se.getPort() == -1 ? 443 : se.getPort() ); sslEngine.beginHandshake(); SSLUtils.setSSLEngine(ctx.getConnection(), sslEngine); } return ctx.getStopAction(); } return ctx.getInvokeAction(); }
@Override public void onClosed(Closeable closeable, CloseType type) throws IOException { if (isGracefullyFinishResponseOnClose()) { // Connection was closed. // This event is fired only for responses, which don't have // associated transfer-encoding or content-length. // We have to complete such a request-response processing gracefully. final FilterChain fc = (FilterChain) connection.getProcessor(); fc.fireEventUpstream(connection, new GracefulCloseEvent(HttpTransactionContext.this), null); } else if (CloseType.REMOTELY.equals(type)) { abort(AsyncHttpProviderUtils.REMOTELY_CLOSED_EXCEPTION); } else { try { closeable.assertOpen(); } catch (IOException ioe) { // unwrap the exception as it was wrapped by assertOpen. abort(ioe.getCause()); } } } };
private boolean establishConnectTunnel(final ProxyServer proxy, final HttpTransactionContext httpCtx, final Uri uri, final FilterChainContext ctx) throws IOException { final Connection connection = ctx.getConnection(); final HttpRequestPacket requestPacket = HttpRequestPacket.builder() .protocol(Protocol.HTTP_1_0) .method(Method.CONNECT) .uri(AsyncHttpProviderUtils.getAuthority(uri)) .build(); setupKeepAlive(requestPacket, connection); httpCtx.establishingTunnel = true; final Request request = httpCtx.getAhcRequest(); addHostHeaderIfNeeded(request, uri, requestPacket); addServiceHeaders(requestPacket); final Realm realm = getRealm(request); addAuthorizationHeader(request, requestPacket, realm, uri, proxy, false); addProxyHeaders(request, requestPacket, realm, proxy, false, true); // turn off SSL, because CONNECT will be sent in plain mode ctx.notifyDownstream(new SSLSwitchingEvent(connection, false)); return sendRequest(httpCtx, ctx, requestPacket, null); }
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == GracefulCloseEvent.class) { // Connection was closed. // This event is fired only for responses, which don't have // associated transfer-encoding or content-length. // We have to complete such a request-response processing gracefully. final GracefulCloseEvent closeEvent = (GracefulCloseEvent) event; final HttpResponsePacket response = closeEvent.getHttpTxContext().responsePacket; response.getProcessingState().getHttpContext().attach(ctx); onHttpPacketParsed(response, ctx); return ctx.getStopAction(); } return ctx.getInvokeAction(); }
ctx.notifyUpstream(new ContinueEvent(context)); return;
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == SSLSwitchingEvent.class) { final SSLSwitchingEvent se = (SSLSwitchingEvent) event; final boolean isSecure = se.isSecure(); CONNECTION_IS_SECURE.set(se.getConnection(), isSecure); // if enabling security - create SSLEngine here, because default // Grizzly SSLFilter will use host/port info from the Connection, rather // than request URL. Specifically this doesn't work with CONNECT tunnels. if (isSecure && SSLUtils.getSSLEngine(ctx.getConnection()) == null) { // if SSLEngine is not yet set for the connection - initialize it final SSLEngine sslEngine = getClientSSLEngineConfigurator() .createSSLEngine(se.getHost(), se.getPort() == -1 ? 443 : se.getPort() ); sslEngine.beginHandshake(); SSLUtils.setSSLEngine(ctx.getConnection(), sslEngine); } return ctx.getStopAction(); } return ctx.getInvokeAction(); }
ctx.notifyDownstream(new SSLSwitchingEvent(connection, secure, uri.getHost(), uri.getPort()));
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { final Object type = event.type(); if (type == ContinueEvent.class) { final ContinueEvent continueEvent = (ContinueEvent) event; continueEvent.getContext().payloadGenerator.continueConfirmed(ctx); } return ctx.getStopAction(); } // ----------------------------------------------------- Private Methods
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == GracefulCloseEvent.class) { // Connection was closed. // This event is fired only for responses, which don't have // associated transfer-encoding or content-length. // We have to complete such a request-response processing gracefully. final GracefulCloseEvent closeEvent = (GracefulCloseEvent) event; final HttpResponsePacket response = closeEvent.getHttpTxContext().responsePacket; response.getProcessingState().getHttpContext().attach(ctx); onHttpPacketParsed(response, ctx); return ctx.getStopAction(); } return ctx.getInvokeAction(); }
@Override public void onClosed(Closeable closeable, CloseType type) throws IOException { if (isGracefullyFinishResponseOnClose() || isKeepAliveDisabled()) { // Connection was closed. // This event is fired only for responses, which don't have // associated transfer-encoding or content-length. // We have to complete such a request-response processing gracefully. final FilterChain fc = (FilterChain) connection.getProcessor(); fc.fireEventUpstream(connection, new GracefulCloseEvent(HttpTransactionContext.this), null); } else if (CloseType.REMOTELY.equals(type)) { abort(AsyncHttpProviderUtils.REMOTELY_CLOSED_EXCEPTION); } else { try { closeable.assertOpen(); } catch (IOException ioe) { // unwrap the exception as it was wrapped by assertOpen. abort(ioe.getCause()); } } } };
ctx.notifyUpstream(new ContinueEvent(context)); return;
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == SSLSwitchingEvent.class) { final SSLSwitchingEvent se = (SSLSwitchingEvent) event; final boolean isSecure = se.isSecure(); CONNECTION_IS_SECURE.set(se.getConnection(), isSecure); // if enabling security - create SSLEngine here, because default // Grizzly SSLFilter will use host/port info from the Connection, rather // than request URL. Specifically this doesn't work with CONNECT tunnels. if (isSecure && SSLUtils.getSSLEngine(ctx.getConnection()) == null) { // if SSLEngine is not yet set for the connection - initialize it final SSLEngine sslEngine = getClientSSLEngineConfigurator() .createSSLEngine(se.getHost(), se.getPort() == -1 ? 443 : se.getPort() ); sslEngine.beginHandshake(); SSLUtils.setSSLEngine(ctx.getConnection(), sslEngine); } return ctx.getStopAction(); } return ctx.getInvokeAction(); }
private boolean establishConnectTunnel(final ProxyServer proxy, final HttpTransactionContext httpCtx, final Uri uri, final FilterChainContext ctx) throws IOException { final Connection connection = ctx.getConnection(); final HttpRequestPacket requestPacket = HttpRequestPacket.builder() .protocol(Protocol.HTTP_1_0) .method(Method.CONNECT) .uri(AsyncHttpProviderUtils.getAuthority(uri)) .build(); setupKeepAlive(requestPacket, connection); httpCtx.establishingTunnel = true; final Request request = httpCtx.getAhcRequest(); addHostHeaderIfNeeded(request, uri, requestPacket); addServiceHeaders(requestPacket); final Realm realm = getRealm(request); addProxyHeaders(request, requestPacket, realm, proxy, false, true); // turn off SSL, because CONNECT will be sent in plain mode ctx.notifyDownstream(new SSLSwitchingEvent(connection, false)); return sendRequest(httpCtx, ctx, requestPacket, null); }
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { final Object type = event.type(); if (type == ContinueEvent.class) { final ContinueEvent continueEvent = (ContinueEvent) event; continueEvent.getContext().payloadGenerator.continueConfirmed(ctx); } return ctx.getStopAction(); } // ----------------------------------------------------- Private Methods
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == GracefulCloseEvent.class) { // Connection was closed. // This event is fired only for responses, which don't have // associated transfer-encoding or content-length. // We have to complete such a request-response processing gracefully. final GracefulCloseEvent closeEvent = (GracefulCloseEvent) event; final HttpResponsePacket response = closeEvent.getHttpTxContext().responsePacket; response.getProcessingState().getHttpContext().attach(ctx); onHttpPacketParsed(response, ctx); return ctx.getStopAction(); } return ctx.getInvokeAction(); }
@Override public void onClosed(Closeable closeable, CloseType type) throws IOException { if (isGracefullyFinishResponseOnClose() || isKeepAliveDisabled()) { // Connection was closed. // This event is fired only for responses, which don't have // associated transfer-encoding or content-length. // We have to complete such a request-response processing gracefully. final FilterChain fc = (FilterChain) connection.getProcessor(); fc.fireEventUpstream(connection, new GracefulCloseEvent(HttpTransactionContext.this), null); } else if (CloseType.REMOTELY.equals(type)) { abort(AsyncHttpProviderUtils.REMOTELY_CLOSED_EXCEPTION); } else { try { closeable.assertOpen(); } catch (IOException ioe) { // unwrap the exception as it was wrapped by assertOpen. abort(ioe.getCause()); } } } };
ctx.notifyUpstream(new ContinueEvent(context)); return;
private boolean establishConnectTunnel(final ProxyServer proxy, final HttpTransactionContext httpCtx, final Uri uri, final FilterChainContext ctx) throws IOException { final Connection connection = ctx.getConnection(); final HttpRequestPacket requestPacket = HttpRequestPacket.builder() .protocol(Protocol.HTTP_1_0) .method(Method.CONNECT) .uri(AsyncHttpProviderUtils.getAuthority(uri)) .build(); setupKeepAlive(requestPacket, connection); httpCtx.establishingTunnel = true; final Request request = httpCtx.getAhcRequest(); addHostHeaderIfNeeded(request, uri, requestPacket); addServiceHeaders(requestPacket); final Realm realm = getRealm(request); addProxyHeaders(request, requestPacket, realm, proxy, false, true); // turn off SSL, because CONNECT will be sent in plain mode ctx.notifyDownstream(new SSLSwitchingEvent(connection, false)); return sendRequest(httpCtx, ctx, requestPacket, null); }
ctx.notifyDownstream(new SSLSwitchingEvent(connection, secure, uri.getHost(), uri.getPort()));