mirror of
https://github.com/kataras/iris.git
synced 2025-12-22 04:17:03 +00:00
add 'DirOptions.PushTargets' for http/2 push on index(es) - #1562
Former-commit-id: 5a3f626ba0fbcf10be979b5a800eba51e88602cd
This commit is contained in:
@@ -164,6 +164,10 @@ type CompressResponseWriter struct {
|
||||
CompressWriter
|
||||
ResponseWriter
|
||||
|
||||
http.Pusher
|
||||
http.Hijacker
|
||||
http.CloseNotifier
|
||||
|
||||
Disabled bool
|
||||
Encoding string
|
||||
Level int
|
||||
@@ -195,12 +199,15 @@ func AcquireCompressResponseWriter(w ResponseWriter, r *http.Request, level int)
|
||||
if level == -1 && encoding == BROTLI {
|
||||
level = 6
|
||||
}
|
||||
// Writer exists, encoding matching and it's valid because it has a non nil encWriter;
|
||||
// just reset to reduce allocations.
|
||||
if v.Encoding == encoding && v.Level == level && v.CompressWriter != nil {
|
||||
v.CompressWriter.Reset(w)
|
||||
return v, nil
|
||||
}
|
||||
|
||||
/*
|
||||
// Writer exists, encoding matching and it's valid because it has a non nil encWriter;
|
||||
// just reset to reduce allocations.
|
||||
if v.Encoding == encoding && v.Level == level && v.CompressWriter != nil {
|
||||
v.CompressWriter.Reset(w)
|
||||
return v, nil
|
||||
}
|
||||
*/
|
||||
|
||||
v.Encoding = encoding
|
||||
|
||||
@@ -213,6 +220,26 @@ func AcquireCompressResponseWriter(w ResponseWriter, r *http.Request, level int)
|
||||
v.CompressWriter = encWriter
|
||||
|
||||
AddCompressHeaders(w.Header(), encoding)
|
||||
|
||||
pusher, ok := w.(http.Pusher)
|
||||
if !ok {
|
||||
pusher = nil // make sure interface value is nil.
|
||||
}
|
||||
|
||||
hijacker, ok := w.(http.Hijacker)
|
||||
if !ok {
|
||||
hijacker = nil
|
||||
}
|
||||
|
||||
closeNotifier, ok := w.(http.CloseNotifier)
|
||||
if !ok {
|
||||
closeNotifier = nil
|
||||
}
|
||||
|
||||
v.Pusher = pusher
|
||||
v.Hijacker = hijacker
|
||||
v.CloseNotifier = closeNotifier
|
||||
|
||||
return v, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user