func transferResponse(session *encoding.ServerSession, request *protocol.RequestHeader, response *protocol.ResponseHeader, input ray.InputStream, output io.Writer) error { session.EncodeResponseHeader(response, output) bodyWriter := session.EncodeResponseBody(request, output) // Optimize for small response packet data, err := input.Read() if err != nil { return err } if err := bodyWriter.Write(data); err != nil { return err } data.Release() if bufferedWriter, ok := output.(*bufio.BufferedWriter); ok { if err := bufferedWriter.SetBuffered(false); err != nil { return err } } if err := buf.PipeUntilEOF(input, bodyWriter); err != nil { return err } if request.Option.Has(protocol.RequestOptionChunkStream) { if err := bodyWriter.Write(buf.NewLocal(8)); err != nil { return err } } return nil }
func handleInput(input ray.InputStream, callback ResponseCallback) { for { data, err := input.Read() if err != nil { break } callback(data) } }