Changeset 23 in code for trunk/morty.go
- Timestamp:
- Oct 30, 2016, 4:54:54 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/morty.go
r21 r23 104 104 type RequestConfig struct { 105 105 Key []byte 106 baseURL *url.URL106 BaseURL *url.URL 107 107 } 108 108 … … 197 197 loc := resp.Header.Peek("Location") 198 198 if loc != nil { 199 url, err := proxifyURI(&RequestConfig{p.Key, parsedURI}, string(loc)) 199 rc := &RequestConfig{Key: p.Key, BaseURL: parsedURI} 200 url, err := rc.ProxifyURI(string(loc)) 200 201 if err == nil { 201 202 ctx.SetStatusCode(resp.StatusCode()) … … 241 242 switch { 242 243 case bytes.Contains(contentType, []byte("css")): 243 sanitizeCSS(&RequestConfig{ p.Key,parsedURI}, ctx, responseBody)244 sanitizeCSS(&RequestConfig{Key: p.Key, BaseURL: parsedURI}, ctx, responseBody) 244 245 case bytes.Contains(contentType, []byte("html")): 245 sanitizeHTML(&RequestConfig{ p.Key,parsedURI}, ctx, responseBody)246 sanitizeHTML(&RequestConfig{Key: p.Key, BaseURL: parsedURI}, ctx, responseBody) 246 247 default: 247 248 ctx.Write(responseBody) … … 291 292 urlEnd := s[5] 292 293 293 if uri, err := proxifyURI(rc,string(css[urlStart:urlEnd])); err == nil {294 if uri, err := rc.ProxifyURI(string(css[urlStart:urlEnd])); err == nil { 294 295 out.Write(css[startIndex:urlStart]) 295 296 out.Write([]byte(uri)) … … 383 384 if bytes.Equal(attr[0], []byte("action")) { 384 385 formURL, _ = url.Parse(string(attr[1])) 385 mergeURIs(rc. baseURL, formURL)386 mergeURIs(rc.BaseURL, formURL) 386 387 break 387 388 } 388 389 } 389 390 if formURL == nil { 390 formURL = rc. baseURL391 formURL = rc.BaseURL 391 392 } 392 393 urlStr := formURL.String() … … 404 405 switch string(tag) { 405 406 case "body": 406 fmt.Fprintf(out, HTML_BODY_EXTENSION, rc. baseURL.String())407 fmt.Fprintf(out, HTML_BODY_EXTENSION, rc.BaseURL.String()) 407 408 case "style": 408 409 state = STATE_DEFAULT … … 493 494 if bytes.Equal(http_equiv, []byte("refresh")) && urlIndex != -1 { 494 495 contentUrl := content[urlIndex+4:] 495 if uri, err := proxifyURI(rc,string(contentUrl)); err == nil {496 if uri, err := rc.ProxifyURI(string(contentUrl)); err == nil { 496 497 fmt.Fprintf(out, ` http-equiv="refresh" content="%surl=%s"`, content[:urlIndex], uri) 497 498 } … … 515 516 switch string(attrName) { 516 517 case "src", "href", "action": 517 if uri, err := proxifyURI(rc,string(attrValue)); err == nil {518 if uri, err := rc.ProxifyURI(string(attrValue)); err == nil { 518 519 fmt.Fprintf(out, " %s=\"%s\"", attrName, uri) 519 520 } else { … … 539 540 } 540 541 541 func proxifyURI(rc *RequestConfig,uri string) (string, error) {542 func (rc *RequestConfig) ProxifyURI(uri string) (string, error) { 542 543 // TODO check malicious data: - e.g. data:script 543 544 if strings.HasPrefix(uri, "data:") { … … 553 554 return "", err 554 555 } 555 mergeURIs(rc. baseURL, u)556 mergeURIs(rc.BaseURL, u) 556 557 557 558 uri = u.String()
Note:
See TracChangeset
for help on using the changeset viewer.