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

net/http: TimeoutHandler does not support Pusher interface #29193

Open
inliquid opened this Issue Dec 12, 2018 · 6 comments

Comments

Projects
None yet
4 participants
@inliquid
Copy link

inliquid commented Dec 12, 2018

When used as a middleware http.TimeoutHandler breaks HTTP/2.0 Server Push mechanism, as its own writer does not support http.Pusher interface.

@Gnouc

This comment has been minimized.

Copy link
Contributor

Gnouc commented Dec 13, 2018

@inliquid can you give an example code?

@inliquid

This comment has been minimized.

Copy link

inliquid commented Dec 13, 2018

  1. Set up middleware
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)
	}
}
  1. timeoutMiddleware returns http.TimeoutHandler and is quite simple
func timeoutMiddleware(next http.Handler) http.Handler {
	return http.TimeoutHandler(next, time.Duration(cfg.ServerHandlerTimeout)*time.Second, http.StatusText(http.StatusServiceUnavailable))
}
  1. Push something
	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 timeoutMiddleware uncommented ok == false and p == nil

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Dec 17, 2018

Change https://golang.org/cl/154383 mentions this issue: net/http: TimeoutHandler supports server Push

@Gnouc

This comment has been minimized.

Copy link
Contributor

Gnouc commented Dec 17, 2018

@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.

@inliquid

This comment has been minimized.

Copy link

inliquid commented Dec 17, 2018

Ok, is there any instruction how to patch and test stdlib with these changes applied?

@Gnouc

This comment has been minimized.

Copy link
Contributor

Gnouc commented Dec 18, 2018

@inliquid I think there's no way unless you re-build your go binary from source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment