build 7
This commit is contained in:
13
main.go
13
main.go
@@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -84,14 +83,10 @@ func httpHandler(w http.ResponseWriter, r *http.Request, pathname string) {
|
|||||||
|
|
||||||
func proxy(w http.ResponseWriter, r *http.Request, client *http.Client, pathname string) {
|
func proxy(w http.ResponseWriter, r *http.Request, client *http.Client, pathname string) {
|
||||||
fmt.Println("Proxy: ", pathname)
|
fmt.Println("Proxy: ", pathname)
|
||||||
r.URL, _ = url.Parse(pathname)
|
req, _ := http.NewRequest(r.Method, pathname, r.Body)
|
||||||
req, _ := http.NewRequest(r.Method, r.URL.String(), r.Body)
|
|
||||||
for k, v := range r.Header {
|
for k, v := range r.Header {
|
||||||
req.Header.Set(k, v[0])
|
req.Header.Set(k, v[0])
|
||||||
}
|
}
|
||||||
for _, value := range r.Cookies() {
|
|
||||||
w.Header().Add(value.Name, value.Value)
|
|
||||||
}
|
|
||||||
res, e := client.Do(req)
|
res, e := client.Do(req)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
fmt.Println("Proxy Error: ", pathname, e)
|
fmt.Println("Proxy Error: ", pathname, e)
|
||||||
@@ -105,7 +100,8 @@ func proxy(w http.ResponseWriter, r *http.Request, client *http.Client, pathname
|
|||||||
res.Header.Set("location", PREFIX+location)
|
res.Header.Set("location", PREFIX+location)
|
||||||
} else {
|
} else {
|
||||||
newReq, _ := http.NewRequest(r.Method, location, res.Body)
|
newReq, _ := http.NewRequest(r.Method, location, res.Body)
|
||||||
proxy(w, newReq, http.DefaultClient, location)
|
client.CheckRedirect = nil
|
||||||
|
proxy(w, newReq, client, location)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,11 +113,12 @@ func proxy(w http.ResponseWriter, r *http.Request, client *http.Client, pathname
|
|||||||
res.Header.Del("Content-Security-Policy-Report-Only")
|
res.Header.Del("Content-Security-Policy-Report-Only")
|
||||||
res.Header.Del("Clear-Site-Data")
|
res.Header.Del("Clear-Site-Data")
|
||||||
|
|
||||||
w.WriteHeader(res.StatusCode)
|
|
||||||
for k, v := range res.Header {
|
for k, v := range res.Header {
|
||||||
w.Header().Set(k, strings.Join(v, ","))
|
w.Header().Set(k, strings.Join(v, ","))
|
||||||
}
|
}
|
||||||
_ = res.Write(w)
|
_ = res.Write(w)
|
||||||
|
w.WriteHeader(res.StatusCode)
|
||||||
|
fmt.Println("result: ", res.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user