|
|
@@ -18,6 +18,7 @@ import (
|
|
|
"v2ray.com/core/common/buf"
|
|
|
"v2ray.com/core/common/errors"
|
|
|
"v2ray.com/core/common/net"
|
|
|
+ http_proto "v2ray.com/core/common/protocol/http"
|
|
|
"v2ray.com/core/common/signal"
|
|
|
"v2ray.com/core/transport/internet"
|
|
|
)
|
|
|
@@ -210,35 +211,6 @@ func (s *Server) handleConnect(ctx context.Context, request *http.Request, reade
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-// @VisibleForTesting
|
|
|
-func StripHopByHopHeaders(header http.Header) {
|
|
|
- // Strip hop-by-hop header basaed on RFC:
|
|
|
- // http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.5.1
|
|
|
- // https://www.mnot.net/blog/2011/07/11/what_proxies_must_do
|
|
|
-
|
|
|
- header.Del("Proxy-Connection")
|
|
|
- header.Del("Proxy-Authenticate")
|
|
|
- header.Del("Proxy-Authorization")
|
|
|
- header.Del("TE")
|
|
|
- header.Del("Trailers")
|
|
|
- header.Del("Transfer-Encoding")
|
|
|
- header.Del("Upgrade")
|
|
|
-
|
|
|
- connections := header.Get("Connection")
|
|
|
- header.Del("Connection")
|
|
|
- if len(connections) == 0 {
|
|
|
- return
|
|
|
- }
|
|
|
- for _, h := range strings.Split(connections, ",") {
|
|
|
- header.Del(strings.TrimSpace(h))
|
|
|
- }
|
|
|
-
|
|
|
- // Prevent UA from being set to golang's default ones
|
|
|
- if len(header.Get("User-Agent")) == 0 {
|
|
|
- header.Set("User-Agent", "")
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
var errWaitAnother = newError("keep alive")
|
|
|
|
|
|
func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, writer io.Writer, dest net.Destination, dispatcher dispatcher.Interface) error {
|
|
|
@@ -263,7 +235,12 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, wri
|
|
|
if len(request.URL.Host) > 0 {
|
|
|
request.Host = request.URL.Host
|
|
|
}
|
|
|
- StripHopByHopHeaders(request.Header)
|
|
|
+ http_proto.RemoveHopByHopHeaders(request.Header)
|
|
|
+
|
|
|
+ // Prevent UA from being set to golang's default ones
|
|
|
+ if len(request.Header.Get("User-Agent")) == 0 {
|
|
|
+ request.Header.Set("User-Agent", "")
|
|
|
+ }
|
|
|
|
|
|
ray, err := dispatcher.Dispatch(ctx, dest)
|
|
|
if err != nil {
|
|
|
@@ -290,7 +267,7 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, wri
|
|
|
responseReader := bufio.NewReaderSize(buf.NewBufferedReader(ray.InboundOutput()), buf.Size)
|
|
|
response, err := http.ReadResponse(responseReader, request)
|
|
|
if err == nil {
|
|
|
- StripHopByHopHeaders(response.Header)
|
|
|
+ http_proto.RemoveHopByHopHeaders(response.Header)
|
|
|
if response.ContentLength >= 0 {
|
|
|
response.Header.Set("Proxy-Connection", "keep-alive")
|
|
|
response.Header.Set("Connection", "keep-alive")
|