From 7ee49f51713d5b85fe3da646a3f3c7e478fd8746 Mon Sep 17 00:00:00 2001 From: Dreamacro <8615343+Dreamacro@users.noreply.github.com> Date: Tue, 30 Mar 2021 16:33:49 +0800 Subject: [PATCH] Fix: HTTP server should close when `Connection` is `close` --- tunnel/connection.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tunnel/connection.go b/tunnel/connection.go index 88d7c3b1..1aba6238 100644 --- a/tunnel/connection.go +++ b/tunnel/connection.go @@ -54,7 +54,12 @@ func handleHTTP(ctx *context.HTTPContext, outbound net.Conn) { goto handleResponse } - if keepAlive || resp.ContentLength >= 0 { + // close conn when header `Connection` is `close` + if resp.Header.Get("Connection") == "close" { + keepAlive = false + } + + if keepAlive { resp.Header.Set("Proxy-Connection", "keep-alive") resp.Header.Set("Connection", "keep-alive") resp.Header.Set("Keep-Alive", "timeout=4")