mirror of
https://github.com/tenox7/wrp.git
synced 2026-04-05 22:01:37 +00:00
fixup connect mode
This commit is contained in:
7
ismap.go
7
ismap.go
@@ -246,6 +246,9 @@ func (rq *wrpReq) captureScreenshot() {
|
||||
return nil
|
||||
}),
|
||||
)
|
||||
if rq.proxy {
|
||||
rq.url = strings.Replace(rq.url, "https://", "http://", 1)
|
||||
}
|
||||
log.Printf("%s Landed on: %s, Height: %v\n", rq.r.RemoteAddr, rq.url, h)
|
||||
height := int64(float64(rq.height) / rq.zoom)
|
||||
if rq.height == 0 && h > 0 {
|
||||
@@ -341,9 +344,9 @@ func (rq *wrpReq) captureScreenshot() {
|
||||
}
|
||||
if rq.proxy {
|
||||
rq.w.Header().Set("Content-Type", "text/html")
|
||||
fmt.Fprintf(rq.w, "<HTML><HEAD><TITLE>%s</TITLE></HEAD><BODY BGCOLOR=\"%s\">"+
|
||||
fmt.Fprintf(rq.w, "<HTML><HEAD>%s<TITLE>%s</TITLE></HEAD><BODY BGCOLOR=\"%s\">"+
|
||||
"<A HREF=\"%s\"><IMG SRC=\"%s\" BORDER=\"0\" WIDTH=\"%d\" HEIGHT=\"%d\" ISMAP></A>"+
|
||||
"</BODY></HTML>", rq.url, *bgColor, mapPath, imgPath, iW, iH)
|
||||
"</BODY></HTML>", rq.baseTag(), rq.url, *bgColor, mapPath, imgPath, iW, iH)
|
||||
} else {
|
||||
rq.printUI(uiParams{
|
||||
bgColor: *bgColor,
|
||||
|
||||
4
shtml.go
4
shtml.go
@@ -371,8 +371,8 @@ func (rq *wrpReq) captureMarkdown() {
|
||||
|
||||
if rq.proxy {
|
||||
rq.w.Header().Set("Content-Type", "text/html")
|
||||
fmt.Fprintf(rq.w, "<HTML><HEAD><TITLE>%s</TITLE></HEAD><BODY BGCOLOR=\"%s\">%s</BODY></HTML>",
|
||||
rq.url, *bgColor, string(asciify([]byte(simplified))))
|
||||
fmt.Fprintf(rq.w, "<HTML><HEAD>%s<TITLE>%s</TITLE></HEAD><BODY BGCOLOR=\"%s\">%s</BODY></HTML>",
|
||||
rq.baseTag(), rq.url, *bgColor, string(asciify([]byte(simplified))))
|
||||
return
|
||||
}
|
||||
rq.printUI(uiParams{
|
||||
|
||||
40
wrp.go
40
wrp.go
@@ -122,6 +122,16 @@ type wrpReq struct {
|
||||
r *http.Request
|
||||
}
|
||||
|
||||
func (rq *wrpReq) baseTag() string {
|
||||
if rq.r.Method != "CONNECT" {
|
||||
return ""
|
||||
}
|
||||
if addr := rq.r.Context().Value(http.LocalAddrContextKey); addr != nil {
|
||||
return fmt.Sprintf(`<BASE HREF="http://%v/">`, addr)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (rq *wrpReq) parseForm() {
|
||||
rq.r.ParseForm()
|
||||
rq.wrpMode = rq.r.FormValue("m")
|
||||
@@ -201,13 +211,14 @@ func (rq *wrpReq) printUI(p uiParams) {
|
||||
}
|
||||
|
||||
func proxyServer(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "CONNECT" {
|
||||
http.Error(w, "CONNECT not supported, use http:// URLs", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
purl := r.URL.String()
|
||||
if r.URL.Scheme == "" {
|
||||
var purl string
|
||||
switch {
|
||||
case r.Method == "CONNECT":
|
||||
purl = "https://" + r.Host
|
||||
case r.URL.Scheme == "":
|
||||
purl = "http://" + r.Host + r.URL.RequestURI()
|
||||
default:
|
||||
purl = r.URL.String()
|
||||
}
|
||||
log.Printf("%s Proxy Request for %s\n", r.RemoteAddr, purl)
|
||||
rq := wrpReq{
|
||||
@@ -227,9 +238,14 @@ func proxyServer(w http.ResponseWriter, r *http.Request) {
|
||||
var currentURL string
|
||||
chromedp.Run(ctx, chromedp.Location(¤tURL))
|
||||
currentURL = strings.Replace(currentURL, "https://", "http://", 1)
|
||||
if currentURL != rq.url {
|
||||
if currentURL != strings.Replace(rq.url, "https://", "http://", 1) {
|
||||
rq.navigate()
|
||||
}
|
||||
rq.url = strings.Replace(rq.url, "https://", "http://", 1)
|
||||
if r.Method == "CONNECT" {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
w.WriteHeader(http.StatusBadGateway)
|
||||
}
|
||||
if rq.wrpMode == "html" {
|
||||
rq.captureMarkdown()
|
||||
return
|
||||
@@ -242,6 +258,7 @@ func isProxyRequest(r *http.Request) bool {
|
||||
}
|
||||
|
||||
func pageServer(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("%s %s %s [%+v]\n", r.RemoteAddr, r.Method, r.URL, r.Host)
|
||||
if isProxyRequest(r) {
|
||||
proxyServer(w, r)
|
||||
return
|
||||
@@ -267,8 +284,6 @@ func pageServer(w http.ResponseWriter, r *http.Request) {
|
||||
func pacServer(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/x-ns-proxy-autoconfig")
|
||||
fmt.Fprintf(w, `function FindProxyForURL(url, host) {
|
||||
if (url.substring(0, 6) == "https:")
|
||||
return "DIRECT";
|
||||
if (isPlainHostName(host) ||
|
||||
host == "localhost" ||
|
||||
isInNet(host, "127.0.0.0", "255.0.0.0") ||
|
||||
@@ -375,6 +390,13 @@ func main() {
|
||||
|
||||
log.Print("Starting WRP http server")
|
||||
srv.Addr = *addr
|
||||
srv.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "CONNECT" {
|
||||
pageServer(w, r)
|
||||
return
|
||||
}
|
||||
http.DefaultServeMux.ServeHTTP(w, r)
|
||||
})
|
||||
err = srv.ListenAndServe()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user