mirror of
https://github.com/netfun2000/rttys_zhaojh329.git
synced 2026-02-27 09:53:24 +08:00
strip default ports from Host header in http proxy
Previously the Host header used the destination address verbatim, including the port even for default ports (80 for HTTPS, 443 for HTTPS). This violates HTTP specifications which require omitting default ports in Host headers. This ensures compliant Host headers like "example.com" instead of "example.com:80" Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
This commit is contained in:
@@ -139,9 +139,7 @@ func doHttpProxy(srv *RttyServer, c net.Conn) {
|
||||
return
|
||||
}
|
||||
|
||||
hostHeaderRewrite := ses.destaddr
|
||||
|
||||
destAddr := genDestAddr(hostHeaderRewrite, ses.https)
|
||||
destAddr, hostHeaderRewrite := genDestAddrAndHost(ses.destaddr, ses.https)
|
||||
|
||||
hpw := &HttpProxyWriter{
|
||||
destAddr: destAddr,
|
||||
@@ -318,10 +316,10 @@ func sendHttpReq(dev *Device, https bool, srcAddr []byte, destAddr []byte, data
|
||||
dev.WriteMsg(proto.MsgTypeHttp, bb)
|
||||
}
|
||||
|
||||
func genDestAddr(addr string, https bool) []byte {
|
||||
func genDestAddrAndHost(addr string, https bool) ([]byte, string) {
|
||||
destIP, destPort, err := httpProxyVaildAddr(addr, https)
|
||||
if err != nil {
|
||||
return nil
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
b := make([]byte, 6)
|
||||
@@ -329,7 +327,14 @@ func genDestAddr(addr string, https bool) []byte {
|
||||
|
||||
binary.BigEndian.PutUint16(b[4:], destPort)
|
||||
|
||||
return b
|
||||
host := addr
|
||||
|
||||
ips, ports, _ := net.SplitHostPort(addr)
|
||||
if ports == "80" || ports == "443" {
|
||||
host = ips
|
||||
}
|
||||
|
||||
return b, host
|
||||
}
|
||||
|
||||
func tcpAddr2Bytes(addr *net.TCPAddr, b []byte) {
|
||||
|
||||
Reference in New Issue
Block a user