Changeset 46 in code
- Timestamp:
- Nov 28, 2016, 5:38:17 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/morty.go
r45 r46 39 39 []byte("embed"), 40 40 //[]byte("iframe"), 41 []byte("math"), 41 42 []byte("script"), 43 []byte("svg"), 42 44 } 43 45 … … 59 61 []byte("height"), 60 62 []byte("hidden"), 63 []byte("hreflang"), 61 64 []byte("id"), 62 65 []byte("lang"), … … 96 99 } 97 100 101 var LINK_REL_SAFE_VALUES [][]byte = [][]byte{ 102 []byte("alternate"), 103 []byte("archives"), 104 []byte("author"), 105 []byte("copyright"), 106 []byte("first"), 107 []byte("help"), 108 []byte("icon"), 109 []byte("index"), 110 []byte("last"), 111 []byte("license"), 112 []byte("manifest"), 113 []byte("next"), 114 []byte("pingback"), 115 []byte("prev"), 116 []byte("publisher"), 117 []byte("search"), 118 []byte("shortcut icon"), 119 []byte("stylesheet"), 120 []byte("up"), 121 } 122 123 var LINK_HTTP_EQUIV_SAFE_VALUES [][]byte = [][]byte{ 124 // X-UA-Compatible will be added automaticaly, so it can be skipped 125 []byte("date"), 126 []byte("last-modified"), 127 []byte("refresh"), // URL rewrite 128 // []byte("location"), TODO URL rewrite 129 []byte("content-language"), 130 } 131 98 132 type Proxy struct { 99 133 Key []byte … … 124 158 ` 125 159 126 var HTML_META_CONTENT_TYPE string = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">" 160 var HTML_HEAD_CONTENT_TYPE string = `<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 161 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 162 ` 127 163 128 164 func (p *Proxy) RequestHandler(ctx *fasthttp.RequestCtx) { … … 167 203 req.SetConnectionClose() 168 204 169 requestURIStr := string(requestURI) 170 171 log.Println("getting", requestURIStr) 172 173 req.SetRequestURI(requestURIStr) 205 reqQuery := parsedURI.Query() 206 ctx.QueryArgs().VisitAll(func(key, value []byte) { 207 reqQuery.Add(string(key), string(value)) 208 }) 209 210 parsedURI.RawQuery = reqQuery.Encode() 211 212 uriStr := parsedURI.String() 213 214 log.Println("getting", uriStr) 215 216 req.SetRequestURI(uriStr) 174 217 req.Header.SetUserAgentBytes([]byte("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36")) 175 218 … … 210 253 } 211 254 } 212 error_message := fmt.Sprintf("invalid response: %d (%s)", resp.StatusCode(), requestURIStr)255 error_message := fmt.Sprintf("invalid response: %d", resp.StatusCode()) 213 256 p.serveMainPage(ctx, resp.StatusCode(), errors.New(error_message)) 214 257 return … … 409 452 410 453 if bytes.Equal(tag, []byte("head")) { 411 fmt.Fprintf(out, HTML_ META_CONTENT_TYPE)454 fmt.Fprintf(out, HTML_HEAD_CONTENT_TYPE) 412 455 } 413 456 … … 487 530 attrValue := attr[1] 488 531 if bytes.Equal(attrName, []byte("rel")) { 489 if bytes.Equal(attrValue, []byte("dns-prefetch")) {532 if !inArray(attrValue, LINK_REL_SAFE_VALUES) { 490 533 exclude = true 491 534 break … … 518 561 if bytes.Equal(attrName, []byte("http-equiv")) { 519 562 http_equiv = bytes.ToLower(attrValue) 563 // exclude some <meta http-equiv="..." ..> 564 if !inArray(http_equiv, LINK_HTTP_EQUIV_SAFE_VALUES) { 565 return 566 } 520 567 } 521 568 if bytes.Equal(attrName, []byte("content")) { … … 526 573 return 527 574 } 528 }529 530 if bytes.Equal(http_equiv, []byte("content-type")) {531 return532 575 } 533 576 … … 547 590 } 548 591 } else { 592 if len(http_equiv) > 0 { 593 fmt.Fprintf(out, ` http-equiv="%s"`, http_equiv) 594 } 549 595 sanitizeAttrs(rc, out, attrs) 550 596 } … … 606 652 return fmt.Sprintf("./?mortyurl=%s", url.QueryEscape(uri)), nil 607 653 } 608 609 654 return fmt.Sprintf("./?mortyhash=%s&mortyurl=%s", hash(uri, rc.Key), url.QueryEscape(uri)), nil 610 655 }
Note:
See TracChangeset
for help on using the changeset viewer.