Archived
1
0

fix http proxy

This commit is contained in:
Jeff Becker 2017-12-29 10:47:54 -05:00
parent 29ab733808
commit 9c89baf68e
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

View File

@ -4,7 +4,6 @@
package srnd
import (
"bufio"
"crypto/tls"
"errors"
"fmt"
@ -291,26 +290,34 @@ func (self *NNTPDaemon) dialOut(proxy_type, proxy_addr, remote_addr string) (con
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")
readLine := func(c net.Conn) (line string, e error) {
var buff [1]byte
var n int
for e == nil {
n, e = c.Read(buff[:])
if n > 0 {
line += string(buff[:])
if buff[0] == 10 {
return
}
}
}
return
}
var line string
line, err = readLine(conn)
if strings.HasPrefix(line, "HTTP/1.1 200") || strings.HasPrefix(line, "HTTP/1.0 200") {
log.Println("http proxy connect accepted")
for err == nil {
line, err = r.ReadString(10)
if line == "\r" || line == "" {
line, err = readLine(conn)
if line == "\r\n" {
break
}
}
if ok {
log.Println("http proxy connect okay")
} else {
err = errors.New("proxy request rejected: " + strings.Trim(firstline, "\r"))
err = errors.New("proxy request rejected: " + strings.Trim(line, "\r"))
log.Println(err)
conn.Close()
conn = nil