check stream state when read/write

merge_conn
fangdingjun 6 years ago
parent 2549e70d74
commit a36277d465

@ -7,6 +7,7 @@ import "C"
import ( import (
"errors" "errors"
"fmt" "fmt"
"io"
"net" "net"
"net/http" "net/http"
"strings" "strings"
@ -31,6 +32,9 @@ type stream struct {
var _ net.Conn = &stream{} var _ net.Conn = &stream{}
func (s *stream) Read(buf []byte) (int, error) { func (s *stream) Read(buf []byte) (int, error) {
if s.closed {
return 0, io.EOF
}
if s.bp != nil { if s.bp != nil {
return s.bp.Read(buf) return s.bp.Read(buf)
} }
@ -38,6 +42,9 @@ func (s *stream) Read(buf []byte) (int, error) {
} }
func (s *stream) WriteHeader(code int) { func (s *stream) WriteHeader(code int) {
if s.closed {
return
}
if s.response == nil { if s.response == nil {
s.response = &http.Response{ s.response = &http.Response{
Proto: "http/2", Proto: "http/2",
@ -91,6 +98,9 @@ func (s *stream) Header() http.Header {
} }
func (s *stream) Write(buf []byte) (int, error) { func (s *stream) Write(buf []byte) (int, error) {
if s.closed {
return 0, io.EOF
}
if s.conn.isServer && s.response == nil { if s.conn.isServer && s.response == nil {
s.WriteHeader(http.StatusOK) s.WriteHeader(http.StatusOK)
} }

Loading…
Cancel
Save