Skip to content

Commit 02359e7

Browse files
initialized doc
1 parent 3f1a281 commit 02359e7

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package httpproxy
22

33
import "net/http"
44

5+
// Context defines context of each proxy connection.
56
type Context struct {
67
Prx *Proxy
78
SessionNo int64

httpproxy.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ import (
66
"sync/atomic"
77
)
88

9+
// ConnectAction specifies action of after the CONNECT.
910
type ConnectAction int
1011

12+
// Constants of ConnectAction type.
1113
const (
1214
ConnectNone = ConnectAction(iota)
1315
ConnectProxy
1416
ConnectMitm
1517
)
1618

19+
// Proxy defines parameters for running an HTTP Proxy. Also implements http.Handler interface for ListenAndServe function.
1720
type Proxy struct {
1821
SessionNo int64
1922
Rt http.RoundTripper
@@ -27,10 +30,12 @@ type Proxy struct {
2730
OnResponse func(ctx *Context, req *http.Request, resp *http.Response)
2831
}
2932

33+
// NewProxy returns a new Proxy has defaults.
3034
func NewProxy() (*Proxy, error) {
3135
return NewProxyWithCert(nil, nil)
3236
}
3337

38+
// NewProxyWithCert returns a new Proxy given certificate and key.
3439
func NewProxyWithCert(caCert, caKey []byte) (result *Proxy, error error) {
3540
result = &Proxy{
3641
Rt: &http.Transport{TLSClientConfig: &tls.Config{},
@@ -49,6 +54,7 @@ func NewProxyWithCert(caCert, caKey []byte) (result *Proxy, error error) {
4954
return
5055
}
5156

57+
// ServeHTTP has been needed for implementing http.Handler.
5258
func (prx *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
5359
ctx := &Context{Prx: prx, SessionNo: atomic.AddInt64(&prx.SessionNo, 1)}
5460

0 commit comments

Comments
 (0)