forked from justmao945/mallory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpac.go
More file actions
50 lines (42 loc) · 889 Bytes
/
pac.go
File metadata and controls
50 lines (42 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package mallory
import (
"io/ioutil"
"net/http"
"net/url"
)
// Provide a simple service for PAC file
type ServicePAC struct {
// Global config
Env *Env
// the PAC file content
PAC []byte
}
// create and init
func CreateServicePAC(e *Env) (self *ServicePAC, err error) {
self = &ServicePAC{Env: e}
url, err := url.Parse(e.PAC)
if err != nil { // treat as a file path
self.PAC, err = ioutil.ReadFile(e.PAC)
return
}
if url.Scheme == "" || url.Scheme == "file" {
self.PAC, err = ioutil.ReadFile(url.Path)
return
}
resp, err := http.Get(e.PAC)
if err != nil {
return
}
defer resp.Body.Close()
_, err = resp.Body.Read(self.PAC)
return
}
// main handler
func (self *ServicePAC) Serve(s *Session) {
s.ResponseWriter.Write(self.PAC)
s.Info("RESPONSE %s", StatusText(http.StatusOK))
}
// return "/pac"
func (self *ServicePAC) Path() string {
return "/pac"
}