fix: end the browser speed test feed without a 410 or 502
This commit is contained in:
1 parent
fd75f324b8
commit
189050b2b6
2 files changed
+15
-10
No files matched your search
@@ -298,18 +298,23 @@ func (s *Server) handleSpeedRelayOpen(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// POST /api/panel/agents/{id}/speed/down - a piece of the browser's upload,
|
||||
// passed on to the agent. 410 once the agent has stopped reading.
|
||||
// passed on to the agent. 204 asks for the next piece, 200 says the agent has
|
||||
// stopped reading.
|
||||
func (s *Server) handleSpeedRelayFeed(w http.ResponseWriter, r *http.Request) {
|
||||
body := http.MaxBytesReader(w, r.Body, speedUpCap)
|
||||
rl := s.relays.get(r.PathValue("id"))
|
||||
if rl == nil {
|
||||
http.Error(w, "gone", http.StatusGone)
|
||||
return
|
||||
if rl != nil {
|
||||
if _, err := io.Copy(rl.downW, body); err == nil {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
}
|
||||
if _, err := io.Copy(rl.downW, http.MaxBytesReader(w, r.Body, speedUpCap)); err != nil {
|
||||
http.Error(w, "gone", http.StatusGone)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
// Take the rest of the piece before answering: an answer sent over an
|
||||
// unread body makes Go drop the connection, which a proxy in front turns
|
||||
// into a 502.
|
||||
_, _ = io.Copy(io.Discard, body)
|
||||
w.Header().Set("Cache-Control", "no-store")
|
||||
_, _ = io.WriteString(w, "done")
|
||||
}
|
||||
|
||||
// GET /api/panel/agents/{id}/speed/up - the agent's upload, for the browser to
|
||||
|
||||
Reference in new issue
Block a user