public void Close() { HttpServerConsole.Instance.WriteLine(LogMessageType.Information, "Closing upstream and downstream connections"); ClientStreamWrapper.Close(); _upStreamConnection.Close(); _isReading = false; IsBusy = false; }
private static void CloseConnection(HttpClientConnection conn) { try { conn.Close(); } catch (IOException) { } }
private void OnHttpResponse(HttpClientConnection connection, byte[] data, int offset, int count) { try { connection.TimeoutTimer.Dispose(); HttpListenerResponse response = connection.Context.Response; response.ContentType = "application/octet-stream"; if (data[offset] == 0x1f && data[offset + 1] == 0x8b && data[offset + 2] == 0x08 && data[offset + 3] == 0x00) { response.AddHeader("Content-Encoding", "gzip"); } response.AddHeader("Access-Control-Allow-Origin", "*"); response.ContentLength64 = count; Stream output = response.OutputStream; output.Write(data, offset, count); output.Close(); connection.Close(); } catch { } }
private void OnHttpResponse(HttpClientConnection connection, byte[] data, int offset, int count) { try { connection.TimeoutTimer.Dispose(); HttpListenerResponse response = connection.Context.Response; response.ContentType = "application/octet-stream"; if (data[offset] == 0x1f && data[offset + 1] == 0x8b && data[offset + 2] == 0x08 && data[offset + 3] == 0x00) { response.AddHeader("Content-Encoding", "gzip"); } response.AddHeader("Access-Control-Allow-Origin", "*"); response.ContentLength64 = count; Stream output = response.OutputStream; output.Write(data, offset, count); output.Close(); connection.Close(); } catch { } }
/// <summary>Creates a tunnel to the target server.</summary> /// <remarks> /// Creates a tunnel to the target server. /// The connection must be established to the (last) proxy. /// A CONNECT request for tunnelling through the proxy will /// be created and sent, the response received and checked. /// This method does <i>not</i> update the connection with /// information about the tunnel, that is left to the caller. /// </remarks> /// <exception cref="Apache.Http.HttpException"></exception> /// <exception cref="System.IO.IOException"></exception> private bool CreateTunnelToTarget(AuthState proxyAuthState, HttpClientConnection managedConn, HttpRoute route, IHttpRequest request, HttpClientContext context) { RequestConfig config = context.GetRequestConfig(); int timeout = config.GetConnectTimeout(); HttpHost target = route.GetTargetHost(); HttpHost proxy = route.GetProxyHost(); HttpResponse response; string authority = target.ToHostString(); IHttpRequest connect = new BasicHttpRequest("CONNECT", authority, request.GetProtocolVersion ()); this.requestExecutor.PreProcess(connect, this.proxyHttpProcessor, context); for (; ;) { if (!managedConn.IsOpen()) { this.connManager.Connect(managedConn, route, timeout > 0 ? timeout : 0, context); } connect.RemoveHeaders(AUTH.ProxyAuthResp); this.authenticator.GenerateAuthResponse(connect, proxyAuthState, context); response = this.requestExecutor.Execute(connect, managedConn, context); int status = response.GetStatusLine().GetStatusCode(); if (status < 200) { throw new HttpException("Unexpected response to CONNECT request: " + response.GetStatusLine ()); } if (config.IsAuthenticationEnabled()) { if (this.authenticator.IsAuthenticationRequested(proxy, response, this.proxyAuthStrategy , proxyAuthState, context)) { if (this.authenticator.HandleAuthChallenge(proxy, response, this.proxyAuthStrategy , proxyAuthState, context)) { // Retry request if (this.reuseStrategy.KeepAlive(response, context)) { this.log.Debug("Connection kept alive"); // Consume response content HttpEntity entity = response.GetEntity(); EntityUtils.Consume(entity); } else { managedConn.Close(); } } else { break; } } else { break; } } } int status_1 = response.GetStatusLine().GetStatusCode(); if (status_1 > 299) { // Buffer response content HttpEntity entity = response.GetEntity(); if (entity != null) { response.SetEntity(new BufferedHttpEntity(entity)); } managedConn.Close(); throw new TunnelRefusedException("CONNECT refused by proxy: " + response.GetStatusLine (), response); } // How to decide on security of the tunnelled connection? // The socket factory knows only about the segment to the proxy. // Even if that is secure, the hop to the target may be insecure. // Leave it to derived classes, consider insecure by default here. return(false); }
/// <exception cref="System.IO.IOException"></exception> public virtual void CloseConnection() { HttpClientConnection conn = GetConnection(); conn.Close(); }