mirror of
https://github.com/minio/minio.git
synced 2025-05-21 17:43:48 -04:00
Add text/event-stream for long running http connections (#7909)
When MinIO is behind a proxy, proxies end up killing clients when no data is seen on the connection, adding the right content-type ensures that proxies do not come in the way.
This commit is contained in:
parent
5a52bc7ff6
commit
5c0acbc6fc
@ -681,12 +681,12 @@ func (a adminAPIHandlers) HealHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Start writing response to client
|
// Start writing response to client
|
||||||
started = true
|
started = true
|
||||||
setCommonHeaders(w)
|
setCommonHeaders(w)
|
||||||
w.Header().Set(xhttp.ContentType, string(mimeJSON))
|
w.Header().Set(xhttp.ContentType, "text/event-stream")
|
||||||
// Set 200 OK status
|
// Set 200 OK status
|
||||||
w.WriteHeader(200)
|
w.WriteHeader(200)
|
||||||
}
|
}
|
||||||
// Send whitespace and keep connection open
|
// Send whitespace and keep connection open
|
||||||
w.Write([]byte("\n\r"))
|
w.Write([]byte(" "))
|
||||||
w.(http.Flusher).Flush()
|
w.(http.Flusher).Flush()
|
||||||
case hr := <-respCh:
|
case hr := <-respCh:
|
||||||
switch hr.apiErr {
|
switch hr.apiErr {
|
||||||
@ -1486,7 +1486,8 @@ func (a adminAPIHandlers) TraceHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Avoid reusing tcp connection if read timeout is hit
|
// Avoid reusing tcp connection if read timeout is hit
|
||||||
// This is needed to make r.Context().Done() work as
|
// This is needed to make r.Context().Done() work as
|
||||||
// expected in case of read timeout
|
// expected in case of read timeout
|
||||||
w.Header().Add(xhttp.Connection, "close")
|
w.Header().Set(xhttp.Connection, "close")
|
||||||
|
w.Header().Set(xhttp.ContentType, "text/event-stream")
|
||||||
|
|
||||||
doneCh := make(chan struct{})
|
doneCh := make(chan struct{})
|
||||||
defer close(doneCh)
|
defer close(doneCh)
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
xhttp "github.com/minio/minio/cmd/http"
|
||||||
"github.com/minio/minio/cmd/logger"
|
"github.com/minio/minio/cmd/logger"
|
||||||
"github.com/minio/minio/pkg/event"
|
"github.com/minio/minio/pkg/event"
|
||||||
"github.com/minio/minio/pkg/event/target"
|
"github.com/minio/minio/pkg/event/target"
|
||||||
@ -246,6 +247,8 @@ func (api objectAPIHandlers) ListenBucketNotificationHandler(w http.ResponseWrit
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.Header().Set(xhttp.ContentType, "text/event-stream")
|
||||||
|
|
||||||
target, err := target.NewHTTPClientTarget(*host, w)
|
target, err := target.NewHTTPClientTarget(*host, w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
|
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
|
||||||
|
@ -2280,6 +2280,7 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite
|
|||||||
w.Write(encodedErrorResponse)
|
w.Write(encodedErrorResponse)
|
||||||
w.(http.Flusher).Flush()
|
w.(http.Flusher).Flush()
|
||||||
}
|
}
|
||||||
|
w.Header().Set(xhttp.ContentType, "text/event-stream")
|
||||||
w = &whiteSpaceWriter{ResponseWriter: w, Flusher: w.(http.Flusher)}
|
w = &whiteSpaceWriter{ResponseWriter: w, Flusher: w.(http.Flusher)}
|
||||||
completeDoneCh := sendWhiteSpace(ctx, w)
|
completeDoneCh := sendWhiteSpace(ctx, w)
|
||||||
objInfo, err := completeMultiPartUpload(ctx, bucket, object, uploadID, completeParts, opts)
|
objInfo, err := completeMultiPartUpload(ctx, bucket, object, uploadID, completeParts, opts)
|
||||||
|
@ -540,6 +540,7 @@ func (s *storageRESTServer) VerifyFile(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
algo := BitrotAlgorithmFromString(algoStr)
|
algo := BitrotAlgorithmFromString(algoStr)
|
||||||
|
w.Header().Set(xhttp.ContentType, "text/event-stream")
|
||||||
doneCh := sendWhiteSpaceVerifyFile(w)
|
doneCh := sendWhiteSpaceVerifyFile(w)
|
||||||
err = s.storage.VerifyFile(volume, filePath, algo, hash, int64(shardSize))
|
err = s.storage.VerifyFile(volume, filePath, algo, hash, int64(shardSize))
|
||||||
<-doneCh
|
<-doneCh
|
||||||
|
Loading…
x
Reference in New Issue
Block a user