Documentation ¶
Overview ¶
Package mallory implements a simple http proxy support direct and GAE remote fetcher
Package singleflight provides a duplicate function call suppression mechanism.
Index ¶
- Constants
- Variables
- func BeautifyDuration(d time.Duration) string
- func BeautifySize(s int64) string
- func CopyHeader(w http.ResponseWriter, r *http.Response)
- func HostOnly(addr string) string
- func RemoveHopHeaders(h http.Header)
- func StatusText(c int) string
- type AccessType
- type Config
- type ConfigFile
- type Direct
- type Group
- type SSH
- type Server
Constants ¶
const ( SmartSrv = iota NormalSrv )
Variables ¶
var (
ErrShouldProxy = errors.New("should proxy")
)
var L = log.New(os.Stdout, "mallory: ", log.Lshortfile|log.LstdFlags)
global logger
Functions ¶
func BeautifyDuration ¶
Duration to e.g. 432ms or 12s, human readable translation
func BeautifySize ¶
func CopyHeader ¶
func CopyHeader(w http.ResponseWriter, r *http.Response)
copy and overwrite headers from r to w
func RemoveHopHeaders ¶
func StatusText ¶
StatusText returns http status text looks like "200 OK"
Types ¶
type AccessType ¶
type AccessType bool
func (AccessType) String ¶
func (t AccessType) String() string
type Config ¶
type Config struct { // file path Path string // config file content File *ConfigFile // File wather Watcher *fsnotify.Watcher // contains filtered or unexported fields }
Provide global config for mallory
type ConfigFile ¶
type ConfigFile struct { // private file file PrivateKey string `json:"id_rsa"` // local addr to listen and serve, default is 127.0.0.1:1315 LocalSmartServer string `json:"local_smart"` // local addr to listen and serve, default is 127.0.0.1:1316 LocalNormalServer string `json:"local_normal"` // remote addr to connect, e.g. ssh://user@linode.my:22 RemoteServer string `json:"remote"` // direct to proxy dial timeout ShouldProxyTimeoutMS int `json:"should_proxy_timeout_ms"` // blocked host list BlockedList []string `json:"blocked"` }
Memory representation for mallory.json
func NewConfigFile ¶
func NewConfigFile(path string) (self *ConfigFile, err error)
Load file from path
func (*ConfigFile) Blocked ¶
func (self *ConfigFile) Blocked(host string) bool
test whether host is in blocked list or not
type Direct ¶
Direct fetcher
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group represents a class of work and forms a namespace in which units of work can be executed with duplicate suppression.
type SSH ¶
type Server ¶
type Server struct { // SmartSrv or NormalSrv Mode int // config file Cfg *Config // direct fetcher Direct *Direct // ssh fetcher, to connect remote proxy server SSH *SSH // a cache BlockedHosts map[string]bool // contains filtered or unexported fields }
func (*Server) ServeHTTP ¶
func (self *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP proxy accepts requests with following two types:
CONNECT Generally, this method is used when the client want to connect server with HTTPS. In fact, the client can do anything he want in this CONNECT way... The request is something like: CONNECT www.google.com:443 HTTP/1.1 Only has the host and port information, and the proxy should not do anything with the underlying data. What the proxy can do is just exchange data between client and server. After accepting this, the proxy should response HTTP/1.1 200 OK to the client if the connection to the remote server is established. Then client and server start to exchange data...
non-CONNECT, such as GET, POST, ... In this case, the proxy should redo the method to the remote server. All of these methods should have the absolute URL that contains the host information. A GET request looks like: GET weibo.com/justmao945/.... HTTP/1.1 which is different from the normal http request: GET /justmao945/... HTTP/1.1 Because we can be sure that all of them are http request, we can only redo the request to the remote server and copy the reponse to client.