-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
93 lines (71 loc) · 1.94 KB
/
main.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings"
)
var _CallMux *CallMux
func main() {
_CallMux = &CallMux{}
go fileServer()
http.ListenAndServe(":8848", _CallMux) //设置监听的端口
}
func fileServer() {
http.Handle("/", http.FileServer(http.Dir("")))
http.ListenAndServe(":88", nil)
}
type CallMux struct {
}
func (this *CallMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Println("1")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Credentials", "true")
url := "http://" + strings.Replace(r.Host, ":8848", "", -1) + r.URL.String()
body, _ := ioutil.ReadAll(r.Body)
if len(body) == 0 {
body = nil
}
var res *http.Response
r.Header.Set("Referer", "http://xinyue.qq.com/act/pc/a20160623dnfryzc/index.shtml")
if r.Header.Get("FUCKCOOKIE") != "" {
r.Header.Set("Cookie", r.Header.Get("FUCKCOOKIE"))
}
fmt.Println(r.Header.Get("Cookie"))
if r.Method == "POST" {
res = httpQuery(url, true, body, r.Header)
} else {
res = httpQuery(url, false, body, r.Header)
}
html, _ := ioutil.ReadAll(res.Body)
fmt.Println("1")
for k, v := range res.Header {
w.Header().Set(k, v[0])
}
cookieStr := ""
cookieJson := make(map[string]string)
for _, v := range res.Cookies() {
cookieStr += v.Name + "=" + v.Value + ";"
cookieJson[v.Name] = v.Value
}
_json, _ := json.Marshal(cookieJson)
w.Header().Set("Set-Cookie", cookieStr)
w.Header().Set("cookie", string(_json))
w.Write(html)
//w.Header().Set(v.Name, v.Value)
}
func httpQuery(url string, is_post bool, data []byte, header http.Header) *http.Response {
client := &http.Client{}
var req *http.Request
if is_post {
req, _ = http.NewRequest("POST", url, bytes.NewReader(data))
//req.Header.Set("Content-Type", "application/x-www-form-urlencoded; Charset=UTF-8")
} else {
req, _ = http.NewRequest("GET", url, nil)
}
req.Header = header
res, _ := client.Do(req)
return res
}