Changeset 96 in code for trunk/morty.go
- Timestamp:
- Aug 11, 2019, 8:34:33 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/morty.go
r95 r96 36 36 37 37 const VERSION = "v0.2.0" 38 39 const MAX_REDIRECT_COUNT = 5 38 40 39 41 var CLIENT *fasthttp.Client = &fasthttp.Client{ … … 288 290 } 289 291 290 parsedURI, err := url.Parse(string(requestURI)) 292 p.ProcessUri(ctx, string(requestURI), 0) 293 } 294 295 func (p *Proxy) ProcessUri(ctx *fasthttp.RequestCtx, requestURI string, redirectCount int) { 296 parsedURI, err := url.Parse(requestURI) 291 297 292 298 if err != nil { … … 339 345 loc := resp.Header.Peek("Location") 340 346 if loc != nil { 341 rc := &RequestConfig{Key: p.Key, BaseURL: parsedURI} 342 url, err := rc.ProxifyURI(loc) 343 if err == nil { 344 ctx.SetStatusCode(resp.StatusCode()) 345 ctx.Response.Header.Add("Location", url) 346 log.Println("redirect to", string(loc)) 347 log.Println("redirect to", string(loc)) 348 if ctx.IsGet() { 349 // GET method: Morty follows the redirect 350 if redirectCount < MAX_REDIRECT_COUNT { 351 p.ProcessUri(ctx, string(loc), redirectCount+1) 352 } else { 353 p.serveMainPage(ctx, 310, errors.New("Too many redirects")) 354 } 347 355 return 356 } else { 357 // Other HTTP methods: Morty does NOT follow the redirect 358 rc := &RequestConfig{Key: p.Key, BaseURL: parsedURI} 359 url, err := rc.ProxifyURI(loc) 360 if err == nil { 361 ctx.SetStatusCode(resp.StatusCode()) 362 ctx.Response.Header.Add("Location", url) 363 return 364 } 348 365 } 349 366 }
Note:
See TracChangeset
for help on using the changeset viewer.