123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package dynamicproxy
- import (
- "net/http"
- "os"
- "strings"
- "imuslab.com/arozos/ReverseProxy/mod/geodb"
- )
- func (h *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
-
- clientIpAddr := geodb.GetRequesterIP(r)
- if h.Parent.Option.GeodbStore.IsBlacklisted(clientIpAddr) {
- w.Header().Set("Content-Type", "text/html; charset=utf-8")
- w.WriteHeader(http.StatusForbidden)
- template, err := os.ReadFile("./web/forbidden.html")
- if err != nil {
- w.Write([]byte("403 - Forbidden"))
- } else {
- w.Write(template)
- }
- return
- }
-
- if h.Parent.Option.RedirectRuleTable.IsRedirectable(r) {
- h.Parent.Option.RedirectRuleTable.HandleRedirect(w, r)
- return
- }
-
- domainOnly := r.Host
- if strings.Contains(r.Host, ":") {
- hostPath := strings.Split(r.Host, ":")
- domainOnly = hostPath[0]
- }
- if strings.Contains(r.Host, ".") {
-
-
- sep := h.Parent.getSubdomainProxyEndpointFromHostname(domainOnly)
- if sep != nil {
- h.subdomainRequest(w, r, sep)
- return
- }
- }
-
- proxyingPath := strings.TrimSpace(r.RequestURI)
- targetProxyEndpoint := h.Parent.getTargetProxyEndpointFromRequestURI(proxyingPath)
- if targetProxyEndpoint != nil {
- h.proxyRequest(w, r, targetProxyEndpoint)
- } else {
- h.proxyRequest(w, r, h.Parent.Root)
- }
- }
|