配置
(web *serverconfigs.HTTPWebConfig, isTop bool, redirects int)
| 479 | |
| 480 | // 配置 |
| 481 | func (this *HTTPRequest) configureWeb(web *serverconfigs.HTTPWebConfig, isTop bool, redirects int) error { |
| 482 | if web == nil || !web.IsOn { |
| 483 | return nil |
| 484 | } |
| 485 | |
| 486 | // 防止跳转次数过多 |
| 487 | if redirects > 8 { |
| 488 | return errors.New("too many redirects") |
| 489 | } |
| 490 | redirects++ |
| 491 | |
| 492 | // uri |
| 493 | rawPath := "" |
| 494 | rawQuery := "" |
| 495 | qIndex := strings.Index(this.uri, "?") // question mark index |
| 496 | if qIndex > -1 { |
| 497 | rawPath = this.uri[:qIndex] |
| 498 | rawQuery = this.uri[qIndex+1:] |
| 499 | } else { |
| 500 | rawPath = this.uri |
| 501 | } |
| 502 | |
| 503 | // redirect |
| 504 | if web.RedirectToHttps != nil && (web.RedirectToHttps.IsPrior || isTop) { |
| 505 | this.web.RedirectToHttps = web.RedirectToHttps |
| 506 | } |
| 507 | |
| 508 | // pages |
| 509 | if len(web.Pages) > 0 { |
| 510 | this.web.Pages = web.Pages |
| 511 | } |
| 512 | |
| 513 | // shutdown |
| 514 | if web.Shutdown != nil && (web.Shutdown.IsPrior || isTop) { |
| 515 | this.web.Shutdown = web.Shutdown |
| 516 | } |
| 517 | |
| 518 | // headers |
| 519 | if web.RequestHeaderPolicyRef != nil && (web.RequestHeaderPolicyRef.IsPrior || isTop) && web.RequestHeaderPolicy != nil { |
| 520 | // TODO 现在是只能选一个有效的设置,未来可以选择是否合并多级别的设置 |
| 521 | this.web.RequestHeaderPolicy = web.RequestHeaderPolicy |
| 522 | } |
| 523 | if web.ResponseHeaderPolicyRef != nil && (web.ResponseHeaderPolicyRef.IsPrior || isTop) && web.ResponseHeaderPolicy != nil { |
| 524 | // TODO 现在是只能选一个有效的设置,未来可以选择是否合并多级别的设置 |
| 525 | this.web.ResponseHeaderPolicy = web.ResponseHeaderPolicy |
| 526 | } |
| 527 | |
| 528 | // root |
| 529 | if web.Root != nil && (web.Root.IsPrior || isTop) { |
| 530 | this.web.Root = web.Root |
| 531 | } |
| 532 | |
| 533 | // remote addr |
| 534 | if web.RemoteAddr != nil && (web.RemoteAddr.IsPrior || isTop) && web.RemoteAddr.IsOn { |
| 535 | this.web.RemoteAddr = web.RemoteAddr |
| 536 | |
| 537 | // check if from proxy |
| 538 | if len(this.web.RemoteAddr.Value) > 0 && this.web.RemoteAddr.Value != "${rawRemoteAddr}" { |
no test coverage detected