-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: TimeoutHandler does not support Pusher interface #29193
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
Comments
@inliquid can you give an example code? |
func setupHandler(r *mux.Router) {
if cfg.ServerUseGzip {
server.Handler = alice.New(
loggerMiddleware,
throttleMiddleware,
//timeoutMiddleware, // <-- breaks Push
compressMiddleWare,
recoverMiddleware,
sessionMiddleware,
authMiddleware,
).Then(r)
} else {
server.Handler = alice.New(
loggerMiddleware,
throttleMiddleware,
//timeoutMiddleware, // <-- breaks Push
recoverMiddleware,
sessionMiddleware,
authMiddleware,
).Then(r)
}
}
func timeoutMiddleware(next http.Handler) http.Handler {
return http.TimeoutHandler(next, time.Duration(cfg.ServerHandlerTimeout)*time.Second, http.StatusText(http.StatusServiceUnavailable))
}
p, ok := w.(http.Pusher)
if ok {
if err := p.Push("/assets/css/pure/pure.css", &http.PushOptions{
//Method: "GET",
Header: http.Header{
"Accept-Encoding": []string{"gzip"},
},
}); err != nil {
logger.Error.Println("Error pushing pure.css!")
}
} When |
Change https://golang.org/cl/154383 mentions this issue: |
@inliquid Ah sorry, the example can be more simple by using code from blog. I mis-interpreted the response when trying it. Can you try above commit if it's fixed for you. |
Ok, is there any instruction how to patch and test stdlib with these changes applied? |
@inliquid I think there's no way unless you re-build your |
Thank you for filing this bug @inliquid and @Gnouc for the preliminary questions. @Gnouc in regards to your question in #29193 (comment) package main
import (
"log"
"net/http"
"time"
)
func main() {
hf := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.Write([]byte("OK"))
})
handler := http.TimeoutHandler(hf, 55*time.Second, "Timed out!")
_, ok := handler.(http.Pusher)
if !ok {
log.Fatal("TimeoutHandler does not implement http.Pusher")
}
log.Print("TimeoutHandler implements http.Pusher")
} which will print out TimeoutHandler does not implement http.Pusher Thanks @Gnouc for the CL, we shall review it for Go1.13. @bradfitz might you have a wishlist for interfaces that many of these helpers should implement? If so, let's review collaborate on this. |
@odeke-em In case we have the wishlist, shall we implement in this issue or raise another one? |
@Gnouc great question! So I think we should spin off another issue after we get the wishlist. That way if any rollback needs to be performed, it'll be piecemeal and this CL will stay in solid :) |
@bradfitz can you please take a look? |
As of Go 1.13rc1, TimeoutHandler supports the Flusher and Pusher interfaces and this change corrects its documentation to say that. Fixes golang#33769 Updates golang#29193
Change https://golang.org/cl/191237 mentions this issue: |
Change https://golang.org/cl/191169 mentions this issue: |
As of Go 1.13rc1, TimeoutHandler supports the Flusher and Pusher interfaces and this change corrects its documentation to say that. Fixes #33769 Updates #29193 Change-Id: Ia0523f7f2e3dc1f8f0b68950b85a7bf81c4abe60 GitHub-Last-Rev: 5310d2c GitHub-Pull-Request: #33770 Reviewed-on: https://go-review.googlesource.com/c/go/+/191237 Reviewed-by: Andrew Bonventre <[email protected]> Run-TryBot: Andrew Bonventre <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
…ch its new interfaces As of Go 1.13rc1, TimeoutHandler supports the Flusher and Pusher interfaces and this change corrects its documentation to say that. Fixes #33769 Updates #29193 Change-Id: Ia0523f7f2e3dc1f8f0b68950b85a7bf81c4abe60 GitHub-Last-Rev: 5310d2c GitHub-Pull-Request: #33770 Reviewed-on: https://go-review.googlesource.com/c/go/+/191237 Reviewed-by: Andrew Bonventre <[email protected]> Run-TryBot: Andrew Bonventre <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> (cherry picked from commit f3e3b71) Reviewed-on: https://go-review.googlesource.com/c/go/+/191169 Reviewed-by: Bryan C. Mills <[email protected]>
As of Go 1.13rc1, TimeoutHandler supports the Flusher and Pusher interfaces and this change corrects its documentation to say that. Fixes golang#33769 Updates golang#29193 Change-Id: Ia0523f7f2e3dc1f8f0b68950b85a7bf81c4abe60 GitHub-Last-Rev: 5310d2c GitHub-Pull-Request: golang#33770 Reviewed-on: https://go-review.googlesource.com/c/go/+/191237 Reviewed-by: Andrew Bonventre <[email protected]> Run-TryBot: Andrew Bonventre <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
When used as a middleware
http.TimeoutHandler
breaks HTTP/2.0 Server Push mechanism, as its own writer does not supporthttp.Pusher
interface.The text was updated successfully, but these errors were encountered: