-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathonlyGetPostProxy.go
More file actions
35 lines (33 loc) · 894 Bytes
/
onlyGetPostProxy.go
File metadata and controls
35 lines (33 loc) · 894 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
package main
import (
"net/http"
"net/http/httputil"
"net/url"
"strings"
"onlyGetPostProxy/conf"
"fmt"
"log"
)
var config = conf.NewConfig()
func NewHostsReverseProxy(target url.URL) *httputil.ReverseProxy {
director := func(req *http.Request) {
// 获取_methods参数
queryForm, err := url.ParseQuery(req.URL.RawQuery)
if err == nil && len(queryForm[config.MethodKey]) > 0 {
req.Method = strings.ToUpper(queryForm[config.MethodKey][0])
}
req.URL.Scheme = target.Scheme
req.URL.Host = target.Host
}
return &httputil.ReverseProxy{Director: director}
}
func main() {
config.ReadConfig()
proxy := NewHostsReverseProxy(url.URL{
Scheme: config.Scheme,
Host: config.ServerHost,
})
fmt.Println("runing at " + config.ListenPort)
fmt.Println("proxy to " + config.Scheme + "://" + config.ServerHost)
log.Fatal(http.ListenAndServe(":" + config.ListenPort, proxy))
}