-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: net/http/httputil: ReverseProxy add a API to get the length of proxy had sent data #57777
Comments
This functionality looks orthogonal to the purpose of ReverseProxy (you could just as easily wrap it in middleware that will do the tracking for you, eg https://pkg.go.dev/github.com/felixge/httpsnoop). |
thanks for your response. felixge/httpsnoop package: // myH is your app's http handler, perhaps a http.ServeMux or similar.
var myH http.Handler
// wrappedH wraps myH in order to log every request.
wrappedH := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
m := httpsnoop.CaptureMetrics(myH, w, r) // This line is block, when header contains "Transfer-Encoding: chunked"
log.Printf(
"%s %s (code=%d dt=%s written=%d)",
r.Method,
r.URL,
m.Code,
m.Duration,
m.Written,
)
})
http.ListenAndServe(":8080", wrappedH) It does not work, when ReverseProxy is used for proxying live streaming by http-flv format and backend http server response data by chunk mode, in other words, Transfer-Encoding: chunked. |
As @seankhliao says, this seems orthogonal to You should be able to build this with a middleware handler that wraps the
|
demo code:
goal:get the length of proxy had sent data, it is successful, but it is block when response is live streaming, because io.ReadAll() can not read EOF or error from streaming。The stream has always existed and has no end。
Design:
The text was updated successfully, but these errors were encountered: