summaryrefslogtreecommitdiff
path: root/http.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-06-29 21:15:29 -0500
committerJeff Carr <[email protected]>2025-06-29 21:15:29 -0500
commit4bc92ccddd52c0a7454247cb226ce085e62394e8 (patch)
tree82c74485c62db923fde2cf4a3e5827e780c02a16 /http.go
initial start after split from gowebdv0.0.1
Diffstat (limited to 'http.go')
-rw-r--r--http.go113
1 files changed, 113 insertions, 0 deletions
diff --git a/http.go b/http.go
new file mode 100644
index 0000000..96a443a
--- /dev/null
+++ b/http.go
@@ -0,0 +1,113 @@
+package main
+
+import (
+ "fmt"
+ "io/ioutil"
+ "net/http"
+ "strings"
+
+ "go.wit.com/log"
+)
+
+// remove '?' part and trailing '/'
+func cleanURL(url string) string {
+ url = "/" + strings.Trim(url, "/")
+ return url
+}
+
+func okHandler(w http.ResponseWriter, r *http.Request) {
+ msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
+ if err != nil {
+ log.Info("ioutil.ReadAll() error =", err)
+ return
+ }
+ // fmt.Fprintln(w, "ioutil.ReadAll() msg =", len(msg))
+ // dumpClient(accessf, clientf, r)
+ var route string
+ // tmp = r.URL.String()
+ route = cleanURL(r.URL.Path)
+ parts := strings.Split(route, "?")
+ log.Info("client sent url =", route, parts)
+ requrl := parts[0]
+
+ log.Warn("forged REQUEST URL =", requrl, "msg =", len(msg))
+ if route == "/" {
+ // indexHeader(w)
+ // indexBodyStart(w)
+ // indexBodyScanConfig(w)
+ // indexDivEnd(w)
+ return
+ }
+ if route == "/patchset" {
+ savePatchset(w, msg)
+ return
+ }
+ if route == "/GetPatchsets" {
+ doSendPatchsets(w)
+ return
+ }
+
+ if route == "/patchsetlist" {
+ listPatchsets(w)
+ return
+ }
+ if route == "/patchsetget" {
+ filename := r.URL.Query().Get("filename")
+ getPatchset(w, filename)
+ return
+ }
+
+ if route == "/goReference.svg" {
+ writeFile(w, "goReference.svg")
+ return
+ }
+ if route == "/skeleton.v2.css" {
+ writeFile(w, "skeleton.v2.css")
+ return
+ }
+ if route == "/favicon.ico" {
+ writeFile(w, "ipv6.png")
+ return
+ }
+ // used for uptime monitor checking
+ if route == "/uptime" {
+ writeFile(w, "uptime.html")
+ return
+ }
+ log.Warn("BAD URL =", requrl)
+ badurl(w, r.URL.String())
+}
+
+func writeFile(w http.ResponseWriter, filename string) {
+ // fmt.Fprintln(w, "GOT TEST?")
+ fullname := "resources/" + filename
+ pfile, err := resources.ReadFile(fullname)
+ if err != nil {
+ log.Println("ERROR:", err)
+ // w.Write(pfile)
+ return
+ }
+
+ var repohtml string
+ repohtml = string(pfile)
+ if filename == "goReference.svg" {
+ w.Header().Set("Content-Type", "image/svg+xml")
+ }
+ fmt.Fprintln(w, repohtml)
+ log.Println("writeFile() found internal file:", filename)
+}
+
+func badurl(w http.ResponseWriter, badurl string) {
+ fmt.Fprintln(w, "<!DOCTYPE html>")
+ fmt.Fprintln(w, "<html>")
+ fmt.Fprintln(w, " <head>")
+ 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, " MANY OF THESE REPOS REQUIRE IPv6.<br>")
+ fmt.Fprintln(w, " <br>")
+ fmt.Fprintln(w, " bad url", badurl, "<a href=\"https://go.wit.com/\">redirecting</a>")
+ fmt.Fprintln(w, " </body>")
+ fmt.Fprintln(w, "</html>")
+}