|
|
|
@ -147,20 +147,26 @@ func transferResponse(session *encoding.ServerSession, request *protocol.Request
|
|
|
|
|
bodyWriter := session.EncodeResponseBody(request, output)
|
|
|
|
|
|
|
|
|
|
// Optimize for small response packet
|
|
|
|
|
if data, err := input.Read(); err == nil {
|
|
|
|
|
if err := bodyWriter.Write(data); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
data, err := input.Read()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if bufferedWriter, ok := output.(*bufio.BufferedWriter); ok {
|
|
|
|
|
bufferedWriter.SetBuffered(false)
|
|
|
|
|
}
|
|
|
|
|
if err := bodyWriter.Write(data); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
data.Release()
|
|
|
|
|
|
|
|
|
|
if err := buf.PipeUntilEOF(input, bodyWriter); err != nil {
|
|
|
|
|
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
|
|
|
|
|