mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
chore(cors): more explanation for flush in ServeHTTP
This commit is contained in:
parent
7dce4c8fbb
commit
fb17ccf5ee
@ -59,6 +59,10 @@ func (h *CORSHandler) addHeader(w http.ResponseWriter, origin string) {
|
||||
// ServeHTTP adds the correct CORS headers based on the origin and returns immediately
|
||||
// with a 200 OK if the method is OPTIONS.
|
||||
func (h *CORSHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
// It is important to flush before leaving the goroutine.
|
||||
// Or it may miss the latest info written.
|
||||
defer w.(http.Flusher).Flush()
|
||||
|
||||
// Write CORS header.
|
||||
if h.Info.OriginAllowed("*") {
|
||||
h.addHeader(w, "*")
|
||||
@ -72,7 +76,4 @@ func (h *CORSHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
|
||||
h.Handler.ServeHTTP(w, req)
|
||||
|
||||
// Flush before leaving to send out all data.
|
||||
w.(http.Flusher).Flush()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user