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 package srnd
import ( import (
"bufio"
"crypto/tls" "crypto/tls"
"errors" "errors"
"fmt" "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) log.Println("dial out via http proxy", proxy_addr)
conn, err = net.Dial("tcp", proxy_addr) conn, err = net.Dial("tcp", proxy_addr)
if err == nil { if err == nil {
var ok bool
_, err = fmt.Fprintf(conn, "CONNECT %s HTTP/1.1\r\n\r\n", remote_addr) _, err = fmt.Fprintf(conn, "CONNECT %s HTTP/1.1\r\n\r\n", remote_addr)
if err == nil { if err == nil {
r := bufio.NewReader(conn) readLine := func(c net.Conn) (line string, e error) {
var line, firstline string var buff [1]byte
firstline, err = r.ReadString(10) var n int
if strings.HasPrefix(firstline, "HTTP/1.1 200") { for e == nil {
ok = true n, e = c.Read(buff[:])
log.Println("http proxy connect accepted") if n > 0 {
} line += string(buff[:])
for err == nil { if buff[0] == 10 {
line, err = r.ReadString(10) return
if line == "\r" || line == "" { }
break }
} }
return
} }
if ok { var line string
log.Println("http proxy connect okay") 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 = readLine(conn)
if line == "\r\n" {
break
}
}
} else { } else {
err = errors.New("proxy request rejected: " + strings.Trim(firstline, "\r")) err = errors.New("proxy request rejected: " + strings.Trim(line, "\r"))
log.Println(err) log.Println(err)
conn.Close() conn.Close()
conn = nil conn = nil