mirror of
https://github.com/ipfs/kubo.git
synced 2025-10-25 02:16:56 +08:00
naming and cleanup
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
@ -204,14 +204,14 @@ func sendResponse(w http.ResponseWriter, req cmds.Request, res cmds.Response) {
|
||||
h.Set(streamHeader, "1")
|
||||
h.Set(transferEncodingHeader, "chunked")
|
||||
|
||||
if err := copyChunks(status, w, out); err != nil {
|
||||
if err := writeResponse(status, w, out); err != nil {
|
||||
log.Error("error while writing stream", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Copies from an io.Reader to a http.ResponseWriter.
|
||||
// Flushes chunks over HTTP stream as they are read (if supported by transport).
|
||||
func copyChunks(status int, w http.ResponseWriter, out io.Reader) error {
|
||||
func writeResponse(status int, w http.ResponseWriter, out io.Reader) error {
|
||||
// hijack the connection so we can write our own chunked output and trailers
|
||||
hijacker, ok := w.(http.Hijacker)
|
||||
if !ok {
|
||||
@ -283,19 +283,3 @@ func sanitizedErrStr(err error) string {
|
||||
s = strings.Split(s, "\r")[0]
|
||||
return s
|
||||
}
|
||||
|
||||
type flushResponse struct {
|
||||
W http.ResponseWriter
|
||||
}
|
||||
|
||||
func (fr *flushResponse) Write(buf []byte) (int, error) {
|
||||
n, err := fr.W.Write(buf)
|
||||
if err != nil {
|
||||
return n, err
|
||||
}
|
||||
|
||||
if flusher, ok := fr.W.(http.Flusher); ok {
|
||||
flusher.Flush()
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user