add removal of proxy header

This commit is contained in:
xvzc 2022-01-15 06:40:57 +09:00
parent 8bda470afd
commit 1e16a454ca
2 changed files with 26 additions and 1 deletions

View File

@ -83,6 +83,28 @@ func (p *HttpPacket) IsConnectMethod() bool {
return p.Method() == "CONNECT"
}
func (p *HttpPacket) RemoveProxyHeader() {
s := string(p.raw)
lines := strings.Split(s, "\n")
for i := 0; i < len(lines); i++ {
if strings.HasPrefix(lines[i], "Proxy-Connection") {
lines[i] = ""
}
}
result := ""
for i := 0; i < len(lines); i++ {
if lines[i] == "" {
continue
}
result += lines[i] + "\n"
}
p.raw = []byte(result)
}
func parse(raw []byte) (string, string, string) {
var firstLine string
for i := 0; i < len(raw); i++ {

View File

@ -48,13 +48,16 @@ func (p *Proxy) Start() {
log.Debug("Client sent data: ", len(b))
pkt := packet.NewHttpPacket(b)
log.Debug("New request: \n\n" + string(pkt.Raw()))
if !pkt.IsValidMethod() {
log.Println("Unsupported method: ", pkt.Method())
return
}
pkt.RemoveProxyHeader()
log.Debug("New request: \n\n" + string(pkt.Raw()))
if pkt.IsConnectMethod() {
log.Debug("[HTTPS] Start")
go conn.HandleHttps(pkt)