mirror of
https://github.com/mjl-/mox.git
synced 2024-12-26 08:23:48 +03:00
fix progress reporting during import through the accounts web page
the import was still processed, but the SSE connection to fetch progress did not work since adding the loggingWriter. found while working on other functionality that uses SSE.
This commit is contained in:
parent
785a38c8b0
commit
91ffa4e99b
2 changed files with 18 additions and 3 deletions
|
@ -129,7 +129,7 @@ func accountHandle(w http.ResponseWriter, r *http.Request) {
|
|||
flusher, ok := w.(http.Flusher)
|
||||
if !ok {
|
||||
log.Error("internal error: ResponseWriter not a http.Flusher")
|
||||
http.Error(w, "500 - internal error - cannot sync to http connection", 500)
|
||||
http.Error(w, "500 - internal error - cannot access underlying connection", 500)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
19
http/web.go
19
http/web.go
|
@ -67,9 +67,14 @@ var (
|
|||
|
||||
// todo: automatic gzip on responses, if client supports it, content is not already compressed. in case of static file only if it isn't too large. skip for certain response content-types (image/*, video/*), or file extensions if there is no identifying content-type. if cpu load isn't too high. if first N kb look compressible and come in quickly enough after first byte (e.g. within 100ms). always flush after 100ms to prevent stalled real-time connections.
|
||||
|
||||
type responseWriterFlusher interface {
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
}
|
||||
|
||||
// http.ResponseWriter that writes access log and tracks metrics at end of response.
|
||||
type loggingWriter struct {
|
||||
W http.ResponseWriter // Calls are forwarded.
|
||||
W responseWriterFlusher // Calls are forwarded.
|
||||
Start time.Time
|
||||
R *http.Request
|
||||
WebsocketRequest bool // Whether request from was websocket.
|
||||
|
@ -84,6 +89,10 @@ type loggingWriter struct {
|
|||
SizeFromClient, SizeToClient int64 // Websocket data.
|
||||
}
|
||||
|
||||
func (w *loggingWriter) Flush() {
|
||||
w.W.Flush()
|
||||
}
|
||||
|
||||
func (w *loggingWriter) Header() http.Header {
|
||||
return w.W.Header()
|
||||
}
|
||||
|
@ -277,8 +286,14 @@ func (s *serve) ServeHTTP(xw http.ResponseWriter, r *http.Request) {
|
|||
ctx := context.WithValue(r.Context(), mlog.CidKey, mox.Cid())
|
||||
r = r.WithContext(ctx)
|
||||
|
||||
wf, ok := xw.(responseWriterFlusher)
|
||||
if !ok {
|
||||
http.Error(xw, "500 - internal server error - cannot access underlying connection"+recvid(r), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
nw := &loggingWriter{
|
||||
W: xw,
|
||||
W: wf,
|
||||
Start: now,
|
||||
R: r,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue