(req *http.Request)
| 33 | var header_regexp = regexp.MustCompile(`^\s*(.*?)\s*:\s*(.*)\s*$`) |
| 34 | |
| 35 | func NewJSRequest(req *http.Request) *JSRequest { |
| 36 | headers := "" |
| 37 | cType := "" |
| 38 | |
| 39 | for name, values := range req.Header { |
| 40 | for _, value := range values { |
| 41 | headers += name + ": " + value + "\r\n" |
| 42 | |
| 43 | if strings.ToLower(name) == "content-type" { |
| 44 | cType = value |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | client_ip := strings.Split(req.RemoteAddr, ":")[0] |
| 50 | client_mac := "" |
| 51 | client_alias := "" |
| 52 | if endpoint := session.I.Lan.GetByIp(client_ip); endpoint != nil { |
| 53 | client_mac = endpoint.HwAddress |
| 54 | client_alias = endpoint.Alias |
| 55 | } |
| 56 | |
| 57 | jreq := &JSRequest{ |
| 58 | Client: map[string]string{"IP": client_ip, "MAC": client_mac, "Alias": client_alias}, |
| 59 | Method: req.Method, |
| 60 | Version: fmt.Sprintf("%d.%d", req.ProtoMajor, req.ProtoMinor), |
| 61 | Scheme: req.URL.Scheme, |
| 62 | Hostname: req.URL.Hostname(), |
| 63 | Port: req.URL.Port(), |
| 64 | Path: req.URL.Path, |
| 65 | Query: req.URL.RawQuery, |
| 66 | ContentType: cType, |
| 67 | Headers: headers, |
| 68 | |
| 69 | req: req, |
| 70 | bodyRead: false, |
| 71 | } |
| 72 | jreq.UpdateHash() |
| 73 | |
| 74 | return jreq |
| 75 | } |
| 76 | |
| 77 | func (j *JSRequest) NewHash() string { |
| 78 | hash := fmt.Sprintf("%s.%s.%s.%s.%s.%s.%s.%s.%s.%s", |
no test coverage detected