修复代理与日志链路的可靠性问题
This commit is contained in:
+6
-3
@@ -26,7 +26,7 @@ type captureWriter struct {
|
||||
}
|
||||
|
||||
func newCaptureWriter(w http.ResponseWriter, max int64) *captureWriter {
|
||||
return &captureWriter{ResponseWriter: w, max: max, status: http.StatusOK}
|
||||
return &captureWriter{ResponseWriter: w, max: max, status: http.StatusOK, sse: newSSEEventTracker(max)}
|
||||
}
|
||||
|
||||
func (c *captureWriter) WriteHeader(code int) {
|
||||
@@ -63,7 +63,7 @@ func (c *captureWriter) Write(p []byte) (int, error) {
|
||||
c.truncated = true
|
||||
}
|
||||
c.written += int64(n)
|
||||
if isStreamResponse(c.Header()) {
|
||||
if c.max > 0 && isStreamResponse(c.Header()) {
|
||||
c.sse.Write(p[:n])
|
||||
}
|
||||
c.flush()
|
||||
@@ -78,7 +78,7 @@ func (c *captureWriter) Flush() {
|
||||
// ConfirmDelivery establishes an observable delivery boundary for responses
|
||||
// whose headers were not followed by a body write.
|
||||
func (c *captureWriter) ConfirmDelivery() {
|
||||
if c.written != 0 {
|
||||
if c.hijacked || c.written != 0 {
|
||||
return
|
||||
}
|
||||
if _, ok := c.ResponseWriter.(http.Flusher); !ok {
|
||||
@@ -89,6 +89,9 @@ func (c *captureWriter) ConfirmDelivery() {
|
||||
}
|
||||
|
||||
func (c *captureWriter) flush() {
|
||||
if c.hijacked {
|
||||
return
|
||||
}
|
||||
if _, ok := c.ResponseWriter.(http.Flusher); !ok {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user