From 29ab733808adfbcaeaff38c840ac931251e68113 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 29 Dec 2017 10:24:03 -0500 Subject: [PATCH] add http proxy support to feeds --- contrib/backends/srndv2/src/srnd/daemon.go | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/contrib/backends/srndv2/src/srnd/daemon.go b/contrib/backends/srndv2/src/srnd/daemon.go index 6ae362b..550cf9f 100644 --- a/contrib/backends/srndv2/src/srnd/daemon.go +++ b/contrib/backends/srndv2/src/srnd/daemon.go @@ -4,6 +4,7 @@ package srnd import ( + "bufio" "crypto/tls" "errors" "fmt" @@ -286,6 +287,36 @@ func (self *NNTPDaemon) dialOut(proxy_type, proxy_addr, remote_addr string) (con err = errors.New("failed to connect via proxy") return } + } else if proxy_type == "http" { + log.Println("dial out via http proxy", proxy_addr) + conn, err = net.Dial("tcp", proxy_addr) + if err == nil { + var ok bool + _, err = fmt.Fprintf(conn, "CONNECT %s HTTP/1.1\r\n\r\n", remote_addr) + if err == nil { + r := bufio.NewReader(conn) + var line, firstline string + firstline, err = r.ReadString(10) + if strings.HasPrefix(firstline, "HTTP/1.1 200") { + ok = true + log.Println("http proxy connect accepted") + } + for err == nil { + line, err = r.ReadString(10) + if line == "\r" || line == "" { + break + } + } + if ok { + log.Println("http proxy connect okay") + } else { + err = errors.New("proxy request rejected: " + strings.Trim(firstline, "\r")) + log.Println(err) + conn.Close() + conn = nil + } + } + } } else { err = errors.New("invalid proxy type: " + proxy_type) }