summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-09-09 12:38:07 -0500
committerJeff Carr <[email protected]>2025-09-09 12:38:07 -0500
commit979fd2f9781c999b7654fc8a186fd28fb12580de (patch)
tree9f6ec14fba157bdaa6e2e27ea135a67c99367f1b
parent24e137c7ece5d2f3fec331fb92c1e20bec9e9505 (diff)
rm old code
-rw-r--r--http.go132
1 files changed, 2 insertions, 130 deletions
diff --git a/http.go b/http.go
index 7e276a4..74f1e66 100644
--- a/http.go
+++ b/http.go
@@ -2,7 +2,6 @@ package main
import (
"fmt"
- "net"
"net/http"
"strings"
@@ -12,42 +11,6 @@ import (
"go.wit.com/log"
)
-// remove '?' part and trailing '/'
-func cleanURL(url string) string {
- url = "/" + strings.Trim(url, "/")
- return url
-}
-
-func getIpSimple(r *http.Request) string {
- host, _, err := net.SplitHostPort(r.RemoteAddr)
- if err != nil {
- log.Printf("could not split host port: %v", err)
- return r.RemoteAddr // Fallback
- }
- return host
-}
-
-// getClientIP inspects the request for common headers to find the true client IP.
-func getClientIP(r *http.Request) string {
- // Caddy sets the X-Forwarded-For header.
- if forwardedFor := r.Header.Get("X-Forwarded-For"); forwardedFor != "" {
- // The header can be a comma-separated list of IPs. The first one is the original client.
- ips := strings.Split(forwardedFor, ",")
- return strings.TrimSpace(ips[0])
- }
-
- // Fallback to RemoteAddr if the header is not present.
- host, _, err := net.SplitHostPort(r.RemoteAddr)
- if err != nil {
- return r.RemoteAddr
- }
- return host
-}
-
-func whoSent(r *http.Request) string {
- return log.Sprintf("%s\t%s", getClientIP(r), r.Header.Get("hostname"))
-}
-
func logReqPB(pb *httppb.HttpRequest) {
log.Info("LOG: httppb.HttpRequest START:")
for i, line := range pb.Log {
@@ -63,11 +26,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
reqPB.Log = append(reqPB.Log, fmt.Sprintf("httppb err %v", err))
}
- who := whoSent(r)
-
route := reqPB.Route
- parts := strings.Split(route, "?")
- requrl := parts[0]
if route == "/" {
w.Header().Set("Content-Type", "text")
@@ -76,8 +35,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return
}
- reqPB.Log = append(reqPB.Log, log.Sprintf("forged REQUEST URL=%s", requrl))
-
if strings.HasPrefix(route, "/repos/") {
pb := gitpb.NewRepos()
if err := pb.Unmarshal(reqPB.ClientData); err == nil {
@@ -167,90 +124,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return
}
- /*
- if route == "/lookup" {
- log.Info("doing lookup len(reqPB.Body) =", len(reqPB.Body))
- found, err := lookupRepos(reqPB.Body)
- if err != nil {
- return
- }
-
- found.SendPB(w)
- return
- }
- */
- /*
- if strings.HasPrefix(route, "/patches/") {
- pb, err := forgepb.GetPatchesFromHttp(reqPB)
- if err != nil {
- log.Info("error converting to patches PB")
- return
- }
- handlePatches(w, pb)
- return
- }
- */
-
- /*
- if route == "/patchset" {
- if err := savePatchset(w, reqPB.Body); err != nil {
- log.Warn("forged /patchset error", err)
- return
- }
- if err := me.forge.SavePatchsets(); err != nil {
- log.Warn("savePatchsets() failed", err)
- return
- }
- return
- }
-
- if route == "/lookup" {
- log.Info("doing lookup len(reqPB.Body) =", len(reqPB.Body))
- found, err := lookupRepos(reqPB.Body)
- if err != nil {
- return
- }
-
- found.SendPB(w)
- return
- }
-
- if route == "/update" {
- log.Info("doing update len(reqPB.Body) =", len(reqPB.Body))
- found, err := updateRepos(reqPB.Body)
- if err != nil {
- return
- }
-
- found.SendPB(w)
- return
- }
- */
-
- /*
- if route == "/GetPatchsets" || route == "/patchsets/get" {
- data, err := me.forge.Patchsets.Marshal()
- if err != nil {
- log.Info("patchsets.Marshal() to wire failed", err)
- return
- }
-
- start := time.Now()
- log.Info("going to w.Write(data) with len", len(data))
- w.Write(data)
-
- age := shell.FormatDuration(time.Since(start))
- log.Printf("Done with xfer in (%s). happy hacking!\n", age)
- return
- }
-
- if route == "/patchsetget" {
- filename := r.URL.Query().Get("filename")
- getPatchset(w, filename)
- return
- }
- */
-
if route == "/goReference.svg" {
w.Header().Set("Content-Type", "image/svg+xml")
writeFile(w, "goReference.svg")
@@ -264,7 +137,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
writeFile(w, "ipv6.png")
return
}
- log.Warn("BAD URL =", requrl, "from", who)
+ log.Warn("BAD URL =", reqPB.URL, "from", reqPB.IP, "author", reqPB.Hostname)
badurl(w, r.URL.String())
}
@@ -281,7 +154,6 @@ func writeFile(w http.ResponseWriter, filename string) {
var repohtml string
repohtml = string(pfile)
fmt.Fprintln(w, repohtml)
- // log.Println("writeFile() found internal file:", filename)
}
func badurl(w http.ResponseWriter, badurl string) {
@@ -291,7 +163,7 @@ func badurl(w http.ResponseWriter, badurl string) {
fmt.Fprintln(w, " <meta http-equiv=\"refresh\" content=\"3; url=https://"+HOSTNAME+"/\">")
fmt.Fprintln(w, " </head>")
fmt.Fprintln(w, " <body>")
- fmt.Fprintln(w, " IPv4 IS NOT SUPPORTED<br>")
+ fmt.Fprintln(w, " IPv4 MAY NOT WORK<br>")
fmt.Fprintln(w, " FORGE REQUIRES IPv6.<br>")
fmt.Fprintln(w, " <br>")
fmt.Fprintln(w, " bad url", badurl, "<a href=\"https://forge.wit.com/\">redirecting</a>")