mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-29 12:01:29 +00:00
Fix write http status after response sent
This commit is contained in:
parent
d77940ab39
commit
55afaa87da
|
@ -93,7 +93,9 @@ func (s *Server) fallbackRequest(ctx context.Context, writer http.ResponseWriter
|
||||||
} else if fErr == os.ErrInvalid {
|
} else if fErr == os.ErrInvalid {
|
||||||
fErr = nil
|
fErr = nil
|
||||||
}
|
}
|
||||||
|
if statusCode > 0 {
|
||||||
writer.WriteHeader(statusCode)
|
writer.WriteHeader(statusCode)
|
||||||
|
}
|
||||||
s.handler.NewError(request.Context(), E.Cause(E.Errors(err, E.Cause(fErr, "fallback connection")), "process connection from ", request.RemoteAddr))
|
s.handler.NewError(request.Context(), E.Cause(E.Errors(err, E.Cause(fErr, "fallback connection")), "process connection from ", request.RemoteAddr))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,14 +110,14 @@ func (s *Server) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
|
||||||
if h, ok := writer.(http.Hijacker); ok {
|
if h, ok := writer.(http.Hijacker); ok {
|
||||||
conn, reader, err := h.Hijack()
|
conn, reader, err := h.Hijack()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.fallbackRequest(request.Context(), writer, request, http.StatusInternalServerError, E.Cause(err, "hijack conn"))
|
s.fallbackRequest(request.Context(), writer, request, 0, E.Cause(err, "hijack conn"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if cacheLen := reader.Reader.Buffered(); cacheLen > 0 {
|
if cacheLen := reader.Reader.Buffered(); cacheLen > 0 {
|
||||||
cache := buf.NewSize(cacheLen)
|
cache := buf.NewSize(cacheLen)
|
||||||
_, err = cache.ReadFullFrom(reader.Reader, cacheLen)
|
_, err = cache.ReadFullFrom(reader.Reader, cacheLen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.fallbackRequest(request.Context(), writer, request, http.StatusInternalServerError, E.Cause(err, "read cache"))
|
s.fallbackRequest(request.Context(), writer, request, 0, E.Cause(err, "read cache"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
conn = bufio.NewCachedConn(conn, cache)
|
conn = bufio.NewCachedConn(conn, cache)
|
||||||
|
@ -141,7 +141,9 @@ func (s *Server) fallbackRequest(ctx context.Context, writer http.ResponseWriter
|
||||||
} else if fErr == os.ErrInvalid {
|
} else if fErr == os.ErrInvalid {
|
||||||
fErr = nil
|
fErr = nil
|
||||||
}
|
}
|
||||||
|
if statusCode > 0 {
|
||||||
writer.WriteHeader(statusCode)
|
writer.WriteHeader(statusCode)
|
||||||
|
}
|
||||||
s.handler.NewError(request.Context(), E.Cause(E.Errors(err, E.Cause(fErr, "fallback connection")), "process connection from ", request.RemoteAddr))
|
s.handler.NewError(request.Context(), E.Cause(E.Errors(err, E.Cause(fErr, "fallback connection")), "process connection from ", request.RemoteAddr))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ func (s *Server) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
|
||||||
}
|
}
|
||||||
wsConn, err := upgrader.Upgrade(writer, request, nil)
|
wsConn, err := upgrader.Upgrade(writer, request, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.fallbackRequest(request.Context(), writer, request, http.StatusBadRequest, E.Cause(err, "upgrade websocket connection"))
|
s.fallbackRequest(request.Context(), writer, request, 0, E.Cause(err, "upgrade websocket connection"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var metadata M.Metadata
|
var metadata M.Metadata
|
||||||
|
@ -116,7 +116,9 @@ func (s *Server) fallbackRequest(ctx context.Context, writer http.ResponseWriter
|
||||||
} else if fErr == os.ErrInvalid {
|
} else if fErr == os.ErrInvalid {
|
||||||
fErr = nil
|
fErr = nil
|
||||||
}
|
}
|
||||||
|
if statusCode > 0 {
|
||||||
writer.WriteHeader(statusCode)
|
writer.WriteHeader(statusCode)
|
||||||
|
}
|
||||||
s.handler.NewError(request.Context(), E.Cause(E.Errors(err, E.Cause(fErr, "fallback connection")), "process connection from ", request.RemoteAddr))
|
s.handler.NewError(request.Context(), E.Cause(E.Errors(err, E.Cause(fErr, "fallback connection")), "process connection from ", request.RemoteAddr))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue