FAQ
Hi.

I'm working on an API server where one of the calls returns a large amount
of data streamed from disk and transformed in some way. I'm using chunked
transfer encoding to return data to the client because I don't way to keep
the entire response in memory. Hypothetically, if an errors occurs reading
from disk or something after I have already started sending the body, how
can I somehow indicate a fault to the client?

func (api *APIServer) ServeHTTP(resp http.ResponseWriter, req
*http.Request) {
     ... process request ...

     for data, err := getData(); err != io.EOF; {
         if err != nil {
             ... indicate response failure somehow ...
             break
         }
         resp.Write(data)
     }
}

With chunked encoding, one way to indicate a failure in this scenario to
avoid sending the final "0\r\n\r\n" so that the response is an invalid HTTP
response. It may not be a good way to indicate *what *error occurred, but
at least the client knows that an error *did* occur. How can I force the
ResponseWriter (which handles chunked encoding for you) to intentionally
send an invalid termination? Or what are some alternatives to report an
error in this situation.

Thanks,
JT

--
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/groups/opt_out.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 3 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJul 21, '13 at 11:54p
activeJul 22, '13 at 2:31a
posts3
users2
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase