FAQ
Hi everyone,

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

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

Thanks!

--
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 golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 4 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMay 2, '14 at 9:23p
activeMay 9, '14 at 7:26a
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase