mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-08-22 02:08:44 +00:00
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package inbound
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
"strings"
|
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
"github.com/Dreamacro/clash/context"
|
|
)
|
|
|
|
// NewHTTP recieve normal http request and return HTTPContext
|
|
func NewHTTP(request *http.Request, conn net.Conn) *context.HTTPContext {
|
|
metadata := parseHTTPAddr(request)
|
|
metadata.Type = C.HTTP
|
|
if ip, port, err := parseAddr(conn.RemoteAddr().String()); err == nil {
|
|
metadata.SrcIP = ip
|
|
metadata.SrcPort = port
|
|
}
|
|
return context.NewHTTPContext(conn, request, metadata)
|
|
}
|
|
|
|
// RemoveHopByHopHeaders remove hop-by-hop header
|
|
func RemoveHopByHopHeaders(header http.Header) {
|
|
// Strip hop-by-hop header based 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))
|
|
}
|
|
}
|