diff options
author | WeidiDeng <[email protected]> | 2024-12-09 14:17:42 +0800 |
---|---|---|
committer | GitHub <[email protected]> | 2024-12-09 14:17:42 +0800 |
commit | c928096c9964b8fb86b23f09fbf5cb71b2c7db2e (patch) | |
tree | 9135744447531cbab9b185986885879954d8695f | |
parent | 17982787aec14b525d7431096eb9b7685654719e (diff) | |
download | caddy-encode-connect.tar.gz caddy-encode-connect.zip |
treat first write and flush for encode response writer to CONNECT request as success if status is not set explicitlyencode-connect
-rw-r--r-- | modules/caddyhttp/encode/encode.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/modules/caddyhttp/encode/encode.go b/modules/caddyhttp/encode/encode.go index e5d744b17..597772ccc 100644 --- a/modules/caddyhttp/encode/encode.go +++ b/modules/caddyhttp/encode/encode.go @@ -270,6 +270,12 @@ func (enc *Encode) Match(rw *responseWriter) bool { // FlushError is an alternative Flush returning an error. It delays the actual Flush of the underlying // ResponseWriterWrapper until headers were written. func (rw *responseWriter) FlushError() error { + // WriteHeader wasn't called and is a CONNECT request, treat it as a success. + // otherwise, wait until header is written. + if rw.isConnect && !rw.wroteHeader && rw.statusCode == 0 { + rw.WriteHeader(http.StatusOK) + } + if !rw.wroteHeader { // flushing the underlying ResponseWriter will write header and status code, // but we need to delay that until we can determine if we must encode and @@ -298,6 +304,12 @@ func (rw *responseWriter) Write(p []byte) (int, error) { return 0, nil } + // WriteHeader wasn't called and is a CONNECT request, treat it as a success. + // otherwise, determine if the response should be compressed. + if rw.isConnect && !rw.wroteHeader && rw.statusCode == 0 { + rw.WriteHeader(http.StatusOK) + } + // sniff content-type and determine content-length if !rw.wroteHeader && rw.config.MinLength > 0 { var gtMinLength bool |