123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package dpcore
- import (
- "mime"
- "net/http"
- "strings"
- "time"
- )
- func (p *ReverseProxy) getFlushInterval(req *http.Request, res *http.Response) time.Duration {
- contentType := req.Header.Get("Content-Type")
- if actualContentType, _, _ := mime.ParseMediaType(contentType); actualContentType == "text/event-stream" {
- return -1
- }
- if req.ContentLength == -1 || p.isBidirectionalStream(req, res) {
- return -1
- }
-
- connectionHeader := req.Header["Connection"]
- if len(connectionHeader) > 0 && strings.Contains(strings.Join(connectionHeader, ","), "keep-alive") {
- return -1
- }
-
- return p.FlushInterval
- }
- func (p *ReverseProxy) isBidirectionalStream(req *http.Request, res *http.Response) bool {
-
-
-
-
-
- ae := req.Header.Get("Accept-Encoding")
- return req.ProtoMajor == 2 &&
- res.ProtoMajor == 2 &&
- res.ContentLength == -1 &&
- (ae == "identity" || ae == "")
- }
|