Skip to content

Commit 981f79e

Browse files
Merge pull request #5 from go-httpproxy/develop
v1.4
2 parents 56cce93 + ebffeab commit 981f79e

File tree

12 files changed

+38
-19
lines changed

12 files changed

+38
-19
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*.cache
55
*.swap
66
*.swp
7+
*.temp
8+
*.tmp
79

810
*.o
911
*.a

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
# Please keep the list sorted.
1111

1212
Orkun Karaduman <[email protected]>
13+
Yasin Özel <[email protected]>

README.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Go HTTP proxy library
1+
# Go HTTP proxy server library
22

33
[![GoDoc](https://godoc.org/github.com/go-httpproxy/httpproxy?status.svg)](https://godoc.org/github.com/go-httpproxy/httpproxy)
44

@@ -9,6 +9,14 @@ attack.
99
It's easy to use. `httpproxy.Proxy` implements `Handler` interface of `net/http`
1010
package to offer `http.ListenAndServe` function.
1111

12+
## Installing
13+
14+
```sh
15+
go get -u github.com/go-httpproxy/httpproxy
16+
# or
17+
go get -u gopkg.in/httpproxy.v1
18+
```
19+
1220
## Usage
1321

1422
Library has two significant structs: Proxy and Context.
@@ -33,29 +41,29 @@ type Proxy struct {
3341
// User data to use free.
3442
UserData interface{}
3543

36-
// Error handler.
44+
// Error callback.
3745
OnError func(ctx *Context, where string, err *Error, opErr error)
3846

39-
// Accept handler. It greets proxy request like ServeHTTP function of
47+
// Accept callback. It greets proxy request like ServeHTTP function of
4048
// http.Handler.
4149
// If it returns true, stops processing proxy request.
4250
OnAccept func(ctx *Context, w http.ResponseWriter, r *http.Request) bool
4351

44-
// Auth handler. If you need authentication, set this handler.
52+
// Auth callback. If you need authentication, set this callback.
4553
// If it returns true, authentication succeeded.
4654
OnAuth func(ctx *Context, authType string, user string, pass string) bool
4755

48-
// Connect handler. It sets connect action and new host.
56+
// Connect callback. It sets connect action and new host.
4957
// If len(newhost) > 0, host changes.
5058
OnConnect func(ctx *Context, host string) (ConnectAction ConnectAction,
5159
newHost string)
5260

53-
// Request handler. It greets remote request.
61+
// Request callback. It greets remote request.
5462
// If it returns non-nil response, stops processing remote request.
5563
OnRequest func(ctx *Context, req *http.Request) (resp *http.Response)
5664

57-
// Response handler. It greets remote response.
58-
// Remote response sends after this handler.
65+
// Response callback. It greets remote response.
66+
// Remote response sends after this callback.
5967
OnResponse func(ctx *Context, req *http.Request, resp *http.Response)
6068

6169
// If ConnectAction is ConnectMitm, it sets chunked to Transfer-Encoding.
@@ -104,7 +112,11 @@ type Context struct {
104112
}
105113
```
106114

107-
### Simple code
115+
## Examples
116+
117+
For more examples, examples/
118+
119+
### examples/go-httpproxy-simple
108120

109121
```go
110122
package main

casigner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func SignHosts(ca tls.Certificate, hosts []string) (*tls.Certificate, error) {
107107
BasicConstraintsValid: true,
108108
}
109109
for _, h := range hosts {
110+
h = stripPort(h)
110111
if ip := net.ParseIP(h); ip != nil {
111112
template.IPAddresses = append(template.IPAddresses, ip)
112113
} else {

context.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ func (ctx *Context) doConnect(w http.ResponseWriter, r *http.Request) (w2 http.R
191191
ctx.ConnectReq = r
192192
ctx.ConnectAction = ConnectProxy
193193
host := r.URL.Host
194+
if !hasPort.MatchString(host) {
195+
host += ":80"
196+
}
194197
if ctx.Prx.OnConnect != nil {
195198
var newHost string
196199
ctx.ConnectAction, newHost = ctx.onConnect(host)
@@ -259,7 +262,7 @@ func (ctx *Context) doConnect(w http.ResponseWriter, r *http.Request) (w2 http.R
259262
remoteConn.Close()
260263
case ConnectMitm:
261264
tlsConfig := &tls.Config{}
262-
cert := ctx.Prx.signer.SignHost(stripPort(host))
265+
cert := ctx.Prx.signer.SignHost(host)
263266
if cert == nil {
264267
hijConn.Close()
265268
ctx.doError("Connect", ErrTLSSignHost, err)

demo/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

demo/simple/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/go-httpproxy-demo/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/go-httpproxy-demo
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/go-httpproxy-simple

0 commit comments

Comments
 (0)