(r *http.Request)
| 575 | } |
| 576 | |
| 577 | func finalHandler(r *http.Request) http.Handler { |
| 578 | requestURIURL, err := url.Parse(r.URL.RequestURI()[1:]) |
| 579 | if err != nil { |
| 580 | return responseWithError(E.Cause(err, "Parse request uri as url")) |
| 581 | } |
| 582 | if common.Any(AcceptDomain, func(it string) bool { |
| 583 | return it == requestURIURL.Host |
| 584 | }) { |
| 585 | if len(requestURIURL.Path) < 2 { |
| 586 | return sendRequestWithURL(requestURIURL) |
| 587 | } |
| 588 | splited := strings.Split(requestURIURL.Path[1:], "/") |
| 589 | var user, repo string |
| 590 | if len(splited) == 0 || (len(splited) == 1 && len(splited[0]) == 0) { |
| 591 | return sendRequestWithURL(requestURIURL) |
| 592 | } |
| 593 | user = splited[0] |
| 594 | if len(splited) > 1 { |
| 595 | repo = splited[1] |
| 596 | } |
| 597 | if repo == "" { |
| 598 | log.InfoContext(r.Context(), "Found user: ", user) |
| 599 | } else { |
| 600 | log.InfoContext(r.Context(), "Found user: ", user, " repository: ", repo) |
| 601 | } |
| 602 | if common.Any(Blacklist, func(it RepoInfo) bool { |
| 603 | result := it.Match(strings.ToLower(user), strings.ToLower(repo)) |
| 604 | if result { |
| 605 | log.InfoContext(r.Context(), "Match blocked repository: ", it.User, "/", it.Repo) |
| 606 | } |
| 607 | return result |
| 608 | }) { |
| 609 | return responseWithWarn("Blocked repository") |
| 610 | } else { |
| 611 | return sendRequestWithURL(requestURIURL) |
| 612 | } |
| 613 | } |
| 614 | if r.Referer() != "" { |
| 615 | rawRefererURL, err := url.Parse(r.Referer()) |
| 616 | if err != nil { |
| 617 | return responseWithError(E.Cause(err, "Parse referer url")) |
| 618 | } |
| 619 | refererURL, err := url.Parse(rawRefererURL.RequestURI()[1:]) |
| 620 | if err != nil { |
| 621 | return responseWithError(E.Cause(err, "Parse referer url request uri as url")) |
| 622 | } |
| 623 | if common.Any(AcceptDomain, func(it string) bool { |
| 624 | return it == refererURL.Host |
| 625 | }) { |
| 626 | finalURL, err := refererURL.Parse(r.URL.RequestURI()) |
| 627 | if err != nil { |
| 628 | return responseWithError(E.Cause(err, "Parse request uri as path with referer url")) |
| 629 | } |
| 630 | return responseWithRedirect(finalURL) |
| 631 | } |
| 632 | } |
| 633 | if requestURIURL.Scheme == "" { |
| 634 | return responseWithError(E.New("URL scheme request")) |
no test coverage detected