proxy

package
v0.0.0-...-b60b3b5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2018 License: GPL-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package proxy implements a http proxy.

Support GET, POST, CONNECT method and so on. Support proxy auth and web management. Support web cache.

Index

Constants

This section is empty.

Variables

View Source
var HTTP200 = []byte("HTTP/1.1 200 Connection Established\r\n\r\n")

HTTP200 http 200 response

View Source
var HTTP401 = []byte("HTTP/1.1 401 Authorization Required\r\nWWW-Authenticate: Basic realm=\"Secure Web\"\r\n\r\n")

HTTP401 http 401 response

View Source
var HTTP407 = []byte("HTTP/1.1 407 Proxy Authorization Required\r\nProxy-Authenticate: Basic realm=\"Secure Proxys\"\r\n\r\n")

HTTP407 http 407 response

Functions

func Check

func Check(user, passwd string) bool

Check checks username and password

func CheckAdmin

func CheckAdmin(user, passwd string) bool

CheckAdmin checks authorization

func ClearHeaders

func ClearHeaders(headers http.Header)

ClearHeaders clear headers.

func CopyHeaders

func CopyHeaders(dst, src http.Header)

CopyHeaders copy headers from source to destination. Nothing would be returned.

func CopyResponse

func CopyResponse(dest *http.Response, src *http.Response)

CopyResponse copys response from src to dest.

func GetBuf

func GetBuf() []byte

GetBuf gets a buffer from default pool.

func NeedAuth

func NeedAuth(rw http.ResponseWriter, challenge []byte) error

NeedAuth requires authorization

func NewServer

func NewServer() *http.Server

NewServer returns a new proxyserver.

func PutBuf

func PutBuf(buf []byte)

PutBuf puts a buffer back default pool.

func RmProxyHeaders

func RmProxyHeaders(req *http.Request)

RmProxyHeaders remove Hop-by-hop headers.

Types

type BufferPool

type BufferPool struct {
	// contains filtered or unexported fields
}

BufferPool holds a pool of buffer

func NewBufferPool

func NewBufferPool(size int) *BufferPool

NewBufferPool creates a new buffer pool.

func (*BufferPool) Get

func (bp *BufferPool) Get() []byte

Get gets a buffer from pool.

func (*BufferPool) Put

func (bp *BufferPool) Put(buf []byte)

Put puts buffer back pool.

type Server

type Server struct {
	// User records user's name
	Tr   *http.Transport
	User string
}

Server is a server of proxy.

func (*Server) Auth

func (proxy *Server) Auth(rw http.ResponseWriter, req *http.Request) bool

Auth provides basic authorization for proxy server.

func (*Server) Ban

func (proxy *Server) Ban(rw http.ResponseWriter, req *http.Request) bool

Ban forbids requested URL in GFWList.

func (*Server) CacheHandler

func (proxy *Server) CacheHandler(rw http.ResponseWriter, req *http.Request)

CacheHandler handles "Get" request

func (*Server) HTTPHandler

func (proxy *Server) HTTPHandler(rw http.ResponseWriter, req *http.Request)

HTTPHandler handles http connections. 处理普通的http请求

func (*Server) HTTPSHandler

func (proxy *Server) HTTPSHandler(rw http.ResponseWriter, req *http.Request)

HTTPSHandler handles any connection which need connect method. 处理https连接,主要用于CONNECT方法

func (*Server) ReverseHandler

func (proxy *Server) ReverseHandler(req *http.Request)

ReverseHandler handles request for reverse proxy.

func (*Server) ServeHTTP

func (proxy *Server) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP will be automatically called by system. ProxyServer implements the Handler interface which need ServeHTTP.

type WebServer

type WebServer struct {
	Port string
}

WebServer is a manager server

func NewWebServer

func NewWebServer() *WebServer

NewWebServer creates a WebServer to manage.

func (*WebServer) HomeHandler

func (ws *WebServer) HomeHandler(rw http.ResponseWriter, req *http.Request)

HomeHandler handles web home page

func (*WebServer) ServeHTTP

func (ws *WebServer) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP handles web admin pages

func (*WebServer) SettingHandler

func (ws *WebServer) SettingHandler(rw http.ResponseWriter, req *http.Request)

SettingHandler allows admin modifies proxy's setting.

func (*WebServer) UserHandler

func (ws *WebServer) UserHandler(rw http.ResponseWriter, req *http.Request)

UserHandler handles user-list page

func (*WebServer) WebAuth

func (ws *WebServer) WebAuth(rw http.ResponseWriter, req *http.Request) error

WebAuth performance authorization.

Source Files

  • auth.go
  • ban.go
  • buf.go
  • cache.go
  • headers.go
  • init.go
  • proxy.go
  • reverse.go
  • web.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL