mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-23 02:26:49 -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 {
|
type flushWriter struct {
|
||||||
w io.Writer
|
w io.Writer
|
||||||
|
d *signal.Done
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fw flushWriter) Write(p []byte) (n int, err error) {
|
func (fw flushWriter) Write(p []byte) (n int, err error) {
|
||||||
|
if fw.d.Done() {
|
||||||
|
return 0, io.ErrClosedPipe
|
||||||
|
}
|
||||||
|
|
||||||
n, err = fw.w.Write(p)
|
n, err = fw.w.Write(p)
|
||||||
if f, ok := fw.w.(http.Flusher); ok {
|
if f, ok := fw.w.(http.Flusher); ok {
|
||||||
f.Flush()
|
f.Flush()
|
||||||
@ -61,8 +66,8 @@ func (l *Listener) ServeHTTP(writer http.ResponseWriter, request *http.Request)
|
|||||||
done := signal.NewDone()
|
done := signal.NewDone()
|
||||||
l.handler(&Connection{
|
l.handler(&Connection{
|
||||||
Reader: request.Body,
|
Reader: request.Body,
|
||||||
Writer: flushWriter{writer},
|
Writer: flushWriter{w: writer, d: done},
|
||||||
Closer: common.NewChainedClosable(request.Body, done),
|
Closer: common.NewChainedClosable(done, request.Body),
|
||||||
Local: l.Addr(),
|
Local: l.Addr(),
|
||||||
Remote: l.Addr(),
|
Remote: l.Addr(),
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user