Skip to content

Commit

Permalink
add support for proxy authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
inconshreveable committed Sep 13, 2013
1 parent 917d636 commit 15e017d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ngrok/client/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func parseArgs() *Options {
proxyAddr := flag.String(
"proxyAddr",
"",
"The address of an http proxy to connect through (ex: proxy.example.org:3128)")
"The address of an http proxy to connect through (ex: [user:pw@]proxy.example.org:3128)")

httpAuth := flag.String(
"httpauth",
Expand Down
15 changes: 15 additions & 0 deletions src/ngrok/conn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"bufio"
"bytes"
"crypto/tls"
"encoding/base64"
"fmt"
"io"
"math/rand"
"net"
"net/http"
"ngrok/log"
"strings"
)

type Conn interface {
Expand Down Expand Up @@ -89,6 +91,15 @@ func Dial(addr, typ string, tlsCfg *tls.Config) (conn *loggedConn, err error) {
}

func DialHttpProxy(proxyAddr, addr, typ string, tlsCfg *tls.Config) (conn *loggedConn, err error) {
var proxyAuth string

// parse the proxy address for authentication credentials
addrParts := strings.Split(proxyAddr, "@")
if len(addrParts) == 2 {
proxyAddr = addrParts[1]
proxyAuth = "Basic " + base64.StdEncoding.EncodeToString([]byte(addrParts[0]))
}

// dial the proxy
if conn, err = Dial(proxyAddr, typ, nil); err != nil {
return
Expand All @@ -99,6 +110,10 @@ func DialHttpProxy(proxyAddr, addr, typ string, tlsCfg *tls.Config) (conn *logge
if err != nil {
return
}

if proxyAuth != "" {
req.Header.Set("Proxy-Authorization", proxyAuth)
}
req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; ngrok)")
req.Write(conn)

Expand Down
2 changes: 1 addition & 1 deletion src/ngrok/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
const (
Proto = "2"
Major = "1"
Minor = "1"
Minor = "2"
)

func MajorMinor() string {
Expand Down

0 comments on commit 15e017d

Please sign in to comment.