diff --git a/src/main/java/org/littleshoot/proxy/impl/ClientToProxyConnection.java b/src/main/java/org/littleshoot/proxy/impl/ClientToProxyConnection.java index 964858fbf..cde4ac55a 100644 --- a/src/main/java/org/littleshoot/proxy/impl/ClientToProxyConnection.java +++ b/src/main/java/org/littleshoot/proxy/impl/ClientToProxyConnection.java @@ -528,7 +528,9 @@ void timedOut(ProxyToServerConnection serverConnection) { @Override protected void timedOut() { // idle timeout fired on the client channel. if we aren't waiting on a response from a server, hang up - if (currentServerConnection == null || this.lastReadTime <= currentServerConnection.lastReadTime) { + // fix : disconnect when connect server error and lastReadTime == 0 + if (currentServerConnection == null || this.lastReadTime <= currentServerConnection.lastReadTime + || currentServerConnection.lastReadTime == 0 && currentServerConnection.is(ConnectionState.DISCONNECTED)) { super.timedOut(); } } diff --git a/src/main/java/org/littleshoot/proxy/impl/ProxyToServerConnection.java b/src/main/java/org/littleshoot/proxy/impl/ProxyToServerConnection.java index b612f5160..f95506121 100644 --- a/src/main/java/org/littleshoot/proxy/impl/ProxyToServerConnection.java +++ b/src/main/java/org/littleshoot/proxy/impl/ProxyToServerConnection.java @@ -424,6 +424,16 @@ protected void disconnected() { } } clientConnection.serverDisconnected(this); + // fix : return BAD_GATEWAY when connect server error and lastReadTime ==0 + if (serverConnection.lastReadTime == 0) { + FullHttpResponse substituteResponse = ProxyUtils.createFullHttpResponse(HttpVersion.HTTP_1_1, + HttpResponseStatus.BAD_GATEWAY, + "Unable to parse response from server"); + HttpHeaders.setKeepAlive(substituteResponse, false); + HttpResponse httpResponse = substituteResponse; + rememberCurrentResponse(httpResponse); + respondWith(httpResponse); + } } @Override