这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ type Context interface {
// WriteContent wraps http.ServeContent in order to handle serving streams
// it will handle Range and Modified (like If-Unmodified-Since) headers.
WriteContent(name string, content io.ReadSeeker, lastModified time.Time)

// Implement the http.Flusher interface
Flush()
}

type hcontext struct {
Expand Down Expand Up @@ -431,3 +434,9 @@ func (c *hcontext) WriteContent(name string, content io.ReadSeeker, lastModified
http.ServeContent(c.ResponseWriter, c.r, name, lastModified, content)
c.closed = true
}

func (c *hcontext) Flush() {
if f, ok := c.ResponseWriter.(http.Flusher); ok {
f.Flush()
}
}
8 changes: 8 additions & 0 deletions middleware/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ func (r *statusRecorder) WriteHeader(statusCode int) {
r.ResponseWriter.WriteHeader(statusCode)
}

// `statusRecorder` implements the Flusher interface if the
// underlying `ResponseWriter` does
func (r *statusRecorder) Flush() {
if f, ok := r.ResponseWriter.(http.Flusher); ok {
f.Flush()
}
}

// Logger creates a new middleware to set a tagged `*zap.SugarLogger` in the
// request context. It debug logs request info. If the current terminal is a
// TTY, it will try to use colored output automatically.
Expand Down