mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-22 00:21:30 +00:00
Fix v2ray http transport server read request
This commit is contained in:
parent
bb63429079
commit
cf778eda4f
|
@ -102,12 +102,20 @@ func (s *Server) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.WriteHeader(http.StatusOK)
|
|
||||||
writer.(http.Flusher).Flush()
|
|
||||||
|
|
||||||
var metadata M.Metadata
|
var metadata M.Metadata
|
||||||
metadata.Source = sHttp.SourceAddress(request)
|
metadata.Source = sHttp.SourceAddress(request)
|
||||||
if h, ok := writer.(http.Hijacker); ok {
|
if h, ok := writer.(http.Hijacker); ok {
|
||||||
|
var requestBody *buf.Buffer
|
||||||
|
if contentLength := int(request.ContentLength); contentLength > 0 {
|
||||||
|
requestBody = buf.NewSize(contentLength)
|
||||||
|
_, err := requestBody.ReadFullFrom(request.Body, contentLength)
|
||||||
|
if err != nil {
|
||||||
|
s.fallbackRequest(request.Context(), writer, request, 0, E.Cause(err, "read request"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writer.WriteHeader(http.StatusOK)
|
||||||
|
writer.(http.Flusher).Flush()
|
||||||
conn, reader, err := h.Hijack()
|
conn, reader, err := h.Hijack()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.fallbackRequest(request.Context(), writer, request, 0, E.Cause(err, "hijack conn"))
|
s.fallbackRequest(request.Context(), writer, request, 0, E.Cause(err, "hijack conn"))
|
||||||
|
@ -122,8 +130,12 @@ func (s *Server) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
|
||||||
}
|
}
|
||||||
conn = bufio.NewCachedConn(conn, cache)
|
conn = bufio.NewCachedConn(conn, cache)
|
||||||
}
|
}
|
||||||
|
if requestBody != nil {
|
||||||
|
conn = bufio.NewCachedConn(conn, requestBody)
|
||||||
|
}
|
||||||
s.handler.NewConnection(request.Context(), conn, metadata)
|
s.handler.NewConnection(request.Context(), conn, metadata)
|
||||||
} else {
|
} else {
|
||||||
|
writer.WriteHeader(http.StatusOK)
|
||||||
conn := NewHTTP2Wrapper(&ServerHTTPConn{
|
conn := NewHTTP2Wrapper(&ServerHTTPConn{
|
||||||
NewHTTPConn(request.Body, writer),
|
NewHTTPConn(request.Body, writer),
|
||||||
writer.(http.Flusher),
|
writer.(http.Flusher),
|
||||||
|
|
Loading…
Reference in a new issue