程序基本实现了对http的完整转发,目前暂不支持https
windows需要在设置中的网络>代理设置为手动,并开启代理服务器,填写ip和端口
// httpForward
package main
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strconv"
"strings"
)
func HttpForward(pattern string, port int) {
http.HandleFunc(pattern, doGo)
strPort := strconv.Itoa(port)
fmt.Print("listenning on :", " ", pattern, " ", strPort, "\n")
err := http.ListenAndServe(":"+strPort, nil)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func doGo(w http.ResponseWriter, r *http.Request) {
//r.host不带http,r.url是完整的url
//fmt.Println(r.Host, " ", r.URL, "\n")
fmt.Println("url: ", r.URL)
//查