1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

make sure writer not buffered

This commit is contained in:
Darien Raymond 2017-11-15 11:23:25 +01:00
parent 5a6022d1ed
commit f3c5df8798
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 5 additions and 8 deletions

View File

@ -121,6 +121,7 @@ func (w *BufferedWriter) SetBuffered(f bool) error {
return nil
}
// ReadFrom implements io.ReaderFrom.
func (w *BufferedWriter) ReadFrom(reader io.Reader) (int64, error) {
var sc SizeCounter
if !w.buffer.IsEmpty() {
@ -130,11 +131,12 @@ func (w *BufferedWriter) ReadFrom(reader io.Reader) (int64, error) {
}
}
w.buffered = false
if readerFrom, ok := w.writer.(io.ReaderFrom); ok {
return readerFrom.ReadFrom(reader)
}
w.buffered = false
err := Copy(NewReader(reader), w, CountSize(&sc))
return sc.Size, err
}

View File

@ -257,13 +257,8 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, rea
request.Header.Set("Connection", "close")
requestWriter := buf.NewBufferedWriter(ray.InboundInput())
if err := request.Write(requestWriter); err != nil {
return err
}
if err := requestWriter.Flush(); err != nil {
return err
}
return nil
common.Must(requestWriter.SetBuffered(false))
return request.Write(requestWriter)
})
responseDone := signal.ExecuteAsync(func() error {