mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
net/http/httputil: allow MIME parameters when detecting SSE in ReverseProxy
This change allows httputil.ReverseProxy to detect SSE (server-sent events)
content when the response's Content-Type header includes MIME parameters,
such as "text/event-stream;charset=utf-8".
Prior to this change the value of the Content-Type header was compared
directly to the literal "text/event-stream". This caused a false-negative
which failed to set the FlushInterval correctly when MIME parameters were
present.
Change-Id: If8bb43efb78787b6519d7fe7599ca018a0da0023
GitHub-Last-Rev: 224518c5eb
GitHub-Pull-Request: golang/go#48427
Reviewed-on: https://go-review.googlesource.com/c/go/+/350509
Trust: Alexander Rakoczy <alex@golang.org>
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Alexander Rakoczy <alex@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
parent
b5904f3de0
commit
4a3daeee63
2 changed files with 22 additions and 1 deletions
|
|
@ -11,6 +11,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"mime"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/internal/ascii"
|
||||
|
|
@ -412,7 +413,7 @@ func (p *ReverseProxy) flushInterval(res *http.Response) time.Duration {
|
|||
|
||||
// For Server-Sent Events responses, flush immediately.
|
||||
// The MIME type is defined in https://www.w3.org/TR/eventsource/#text-event-stream
|
||||
if resCT == "text/event-stream" {
|
||||
if baseCT, _, _ := mime.ParseMediaType(resCT); baseCT == "text/event-stream" {
|
||||
return -1 // negative means immediately
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1194,6 +1194,26 @@ func TestSelectFlushInterval(t *testing.T) {
|
|||
p: &ReverseProxy{FlushInterval: 0},
|
||||
want: -1,
|
||||
},
|
||||
{
|
||||
name: "server-sent events with media-type parameters overrides non-zero",
|
||||
res: &http.Response{
|
||||
Header: http.Header{
|
||||
"Content-Type": {"text/event-stream;charset=utf-8"},
|
||||
},
|
||||
},
|
||||
p: &ReverseProxy{FlushInterval: 123},
|
||||
want: -1,
|
||||
},
|
||||
{
|
||||
name: "server-sent events with media-type parameters overrides zero",
|
||||
res: &http.Response{
|
||||
Header: http.Header{
|
||||
"Content-Type": {"text/event-stream;charset=utf-8"},
|
||||
},
|
||||
},
|
||||
p: &ReverseProxy{FlushInterval: 0},
|
||||
want: -1,
|
||||
},
|
||||
{
|
||||
name: "Content-Length: -1, overrides non-zero",
|
||||
res: &http.Response{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue