diff --git a/wrp.go b/wrp.go index aeb02f6..2214b50 100644 --- a/wrp.go +++ b/wrp.go @@ -21,14 +21,10 @@ import ( "strconv" "strings" "time" - "encoding/json" - "encoding/base64" - "net" "github.com/chromedp/cdproto/emulation" "github.com/chromedp/cdproto/runtime" - "github.com/chromedp/cdproto/cdp" "github.com/chromedp/chromedp" "github.com/ericpauley/go-quantize/quantize" @@ -40,6 +36,7 @@ var ( ctx context.Context cancel context.CancelFunc gifmap = make(map[string]bytes.Buffer) + ismap = make(map[string]Params) ) // Params - Page Configuration Parameters @@ -50,18 +47,11 @@ type Params struct { H int64 // height S float64 // scale C int64 // #colors - r string // remote addr - l string // local addr } -func (p *Params) parseParams(req *http.Request) { +func (p *Params) parseForm(req *http.Request) { req.ParseForm() - p.r = string(req.RemoteAddr) - p.l = req.Context().Value(http.LocalAddrContextKey).(*net.TCPAddr).IP.String() p.U = req.FormValue("url") - var x,y int64 - fmt.Sscanf(req.URL.RawQuery, "%d,%d", &x, &y) - log.Printf("%s Page Request for %s url=\"%s\" [%+v]\n", req.RemoteAddr, req.URL.Path, p.U, req.URL.RawQuery) if len(p.U) > 1 && !strings.HasPrefix(p.U, "http") { p.U = fmt.Sprintf("http://www.google.com/search?q=%s", url.QueryEscape(p.U)) } @@ -74,8 +64,8 @@ func (p *Params) parseParams(req *http.Request) { p.P = 0 } p.W, _ = strconv.ParseInt(req.FormValue("w"), 10, 64) - if p.P < 10 { - p.P = 1024 + if p.W < 10 { + p.W = 1024 } p.H, _ = strconv.ParseInt(req.FormValue("h"), 10, 64) if p.H < 10 { @@ -89,13 +79,10 @@ func (p *Params) parseParams(req *http.Request) { if p.C < 2 || p.C > 256 { p.C = 256 } - m, _ := json.Marshal(*p) - log.Printf("DEBUG: Struct: %+v Json: %s Base64: %s\n", p, string(m), base64.StdEncoding.EncodeToString([]byte(m))) + log.Printf("Params from Form: %+v\n", p) } -func pageServer(out http.ResponseWriter, req *http.Request) { - var p Params - p.parseParams(req) +func (p Params) printPage(out http.ResponseWriter) { out.Header().Set("Content-Type", "text/html") fmt.Fprintf(out, "\n", version) fmt.Fprintf(out, "\n
Web Rendering Proxy Version %s | Shutdown WRP\n\n", p.W, p.H, p.S, p.C, version) +} + +func (p Params) printFooter(out http.ResponseWriter) { + fmt.Fprintf(out, "\n