(redirToPort uint, matcherSet MatcherSet)
| 542 | } |
| 543 | |
| 544 | func (app *App) makeRedirRoute(redirToPort uint, matcherSet MatcherSet) Route { |
| 545 | redirTo := "https://{http.request.host}" |
| 546 | |
| 547 | // since this is an external redirect, we should only append an explicit |
| 548 | // port if we know it is not the officially standardized HTTPS port, and, |
| 549 | // notably, also not the port that Caddy thinks is the HTTPS port (the |
| 550 | // configurable HTTPSPort parameter) - we can't change the standard HTTPS |
| 551 | // port externally, so that config parameter is for internal use only; |
| 552 | // we also do not append the port if it happens to be the HTTP port as |
| 553 | // well, obviously (for example, user defines the HTTP port explicitly |
| 554 | // in the list of listen addresses for a server) |
| 555 | if redirToPort != uint(app.httpPort()) && |
| 556 | redirToPort != uint(app.httpsPort()) && |
| 557 | redirToPort != DefaultHTTPPort && |
| 558 | redirToPort != DefaultHTTPSPort { |
| 559 | redirTo += ":" + strconv.Itoa(int(redirToPort)) |
| 560 | } |
| 561 | |
| 562 | redirTo += "{http.request.uri}" |
| 563 | return Route{ |
| 564 | MatcherSets: []MatcherSet{matcherSet}, |
| 565 | Handlers: []MiddlewareHandler{ |
| 566 | StaticResponse{ |
| 567 | StatusCode: WeakString(strconv.Itoa(http.StatusPermanentRedirect)), |
| 568 | Headers: http.Header{ |
| 569 | "Location": []string{redirTo}, |
| 570 | }, |
| 571 | Close: true, |
| 572 | }, |
| 573 | }, |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | func httpsRRALPNs(srv *Server) []string { |
| 578 | alpn := make(map[string]struct{}, 3) |
no test coverage detected