mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 10:08:15 -05:00
protect against writing to closed body
This commit is contained in:
parent
bf5e93efd7
commit
e647292b9a
@ -31,9 +31,14 @@ func (l *Listener) Close() error {
|
||||
|
||||
type flushWriter struct {
|
||||
w io.Writer
|
||||
d *signal.Done
|
||||
}
|
||||
|
||||
func (fw flushWriter) Write(p []byte) (n int, err error) {
|
||||
if fw.d.Done() {
|
||||
return 0, io.ErrClosedPipe
|
||||
}
|
||||
|
||||
n, err = fw.w.Write(p)
|
||||
if f, ok := fw.w.(http.Flusher); ok {
|
||||
f.Flush()
|
||||
@ -61,8 +66,8 @@ func (l *Listener) ServeHTTP(writer http.ResponseWriter, request *http.Request)
|
||||
done := signal.NewDone()
|
||||
l.handler(&Connection{
|
||||
Reader: request.Body,
|
||||
Writer: flushWriter{writer},
|
||||
Closer: common.NewChainedClosable(request.Body, done),
|
||||
Writer: flushWriter{w: writer, d: done},
|
||||
Closer: common.NewChainedClosable(done, request.Body),
|
||||
Local: l.Addr(),
|
||||
Remote: l.Addr(),
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user