I'm implementing an HTTP service in Go where I receive a potentially
long-running file upload from a user. I want to time out if I do not
receive data from the user for more than N seconds, but as long as I'm
receiving data I want the request to continue indefinitely. What's the best
way to do this? Currently I'm using hijacker as in the example at
http://golang.org/pkg/net/http/#Hijacker. I hijack the connection at the
top of my Handler and I call
conn.SetReadDeadline(time.Now().Add(readIdleTimeout)) repeatedly while I
loop over getting data out of the bufrw.
There are two problems I see with this, one minor and the other less minor.
The minor one is that I have to inject myself into the buffer flow by
manually pulling data out of bufrw and putting it into a new buffer
(instead of just giving the original bufrw to the code needing the uploaded
data), which is slightly less efficient. The less minor one is that (as I
understand it) with hijacking I lose the ability to reuse connections, and
if I use SSL then reconstructing the request for every upload can get very
Is there a better way to do this? If it's helpful I can put together an
example but I was hoping this would be enough info. The most ideal solution
in my mind would be to implement a ReadWriteTimeout in http.Server which
operates not on an absolute basis but instead on time-since-last-data-seen
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firstname.lastname@example.org.
For more options, visit https://groups.google.com/d/optout.