-
Notifications
You must be signed in to change notification settings - Fork 242
/
handler.go
42 lines (37 loc) · 857 Bytes
/
handler.go
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
package wechat_spider
import (
"log"
"net/http"
"os"
"reflect"
"spiderx/utils"
"strings"
"github.com/elazarl/goproxy"
)
var (
Verbose = false
Logger = log.New(os.Stderr, "", log.LstdFlags)
)
func ProxyHandle(proc Processor) func(resp *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
return func(resp *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
if ctx.Req.URL.Path == `/mp/getmasssendmsg` && !strings.Contains(ctx.Req.URL.RawQuery, `f=json`) {
var data []byte
var err error
data, resp.Body, err = utils.CopyReader(resp.Body)
if err != nil {
return resp
}
t := reflect.TypeOf(proc)
v := reflect.New(t.Elem())
p := v.Interface().(Processor)
go func() {
err = p.Process(ctx.Req, data)
if err != nil {
Logger.Println(err.Error())
}
p.Output()
}()
}
return resp
}
}