summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-09-06 18:43:23 -0500
committerJeff Carr <[email protected]>2025-09-06 18:48:53 -0500
commit4e5a34b772db9df404b0b927f3ee9b9b54f65cdd (patch)
treed8d1c28655f972aa5b72823d7571bcce68d07815
parentf8b2ff5acedc1835cee10acca49649d1957ed781 (diff)
convert http req directly to PB
-rw-r--r--Makefile4
-rw-r--r--handlePatches.go7
-rw-r--r--http.go46
3 files changed, 32 insertions, 25 deletions
diff --git a/Makefile b/Makefile
index 5a29ece..a58aff9 100644
--- a/Makefile
+++ b/Makefile
@@ -3,14 +3,14 @@
VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
-all: build
+all: build-verbose
./forged merge
build: goimports
GO111MODULE=off go build \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
-verbose:
+build-verbose:
GO111MODULE=off go build -v -x \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
diff --git a/handlePatches.go b/handlePatches.go
index 3a0317c..f270d74 100644
--- a/handlePatches.go
+++ b/handlePatches.go
@@ -5,6 +5,7 @@ import (
"strings"
"go.wit.com/lib/protobuf/forgepb"
+ "go.wit.com/lib/protobuf/httppb"
"go.wit.com/log"
)
@@ -33,6 +34,12 @@ func handlePatches(w http.ResponseWriter, r *http.Request, data []byte) error {
return nil
}
+func makePatchesPB(reqPB *httppb.HttpRequest) (*forgepb.Patches, error) {
+ pb := forgepb.NewPatches()
+ err := pb.Unmarshal(reqPB.Body)
+ return pb, err
+}
+
func sendPatchesError(w http.ResponseWriter, r *forgepb.Patches, err error) error {
log.Info("send error back to user", err)
return nil
diff --git a/http.go b/http.go
index fce515a..a88d6c3 100644
--- a/http.go
+++ b/http.go
@@ -2,13 +2,13 @@ package main
import (
"fmt"
- "io/ioutil"
"net"
"net/http"
"strings"
"time"
"go.wit.com/lib/gui/shell"
+ "go.wit.com/lib/protobuf/httppb"
"go.wit.com/log"
)
@@ -49,15 +49,14 @@ func whoSent(r *http.Request) string {
}
func okHandler(w http.ResponseWriter, r *http.Request) {
- // something appears to be buggy. always get this first I guess
- msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
- r.Body.Close()
- log.Info("TRYING TO MARSHAL bytes:", len(msg), err)
+ reqPB, err := httppb.ReqToPB(r)
+ if err != nil {
+ log.Info("something crazy err", err)
+ }
who := whoSent(r)
- var route string
- route = cleanURL(r.URL.Path)
+ route := reqPB.Route
parts := strings.Split(route, "?")
// log.Info("client sent url =", route, parts)
requrl := parts[0]
@@ -78,7 +77,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
log.Warn("forged REQUEST URL =", requrl, "from =", who)
if strings.HasPrefix(route, "/patches/") {
- handlePatches(w, r, msg)
+ pb, err := makePatchesPB(reqPB)
+ log.Info("err", err, "len", pb.Len())
return
}
@@ -88,7 +88,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
if route == "/patchset" {
- if err := savePatchset(w, msg); err != nil {
+ if err := savePatchset(w, reqPB.Body); err != nil {
log.Warn("forged /patchset error", err)
return
}
@@ -100,8 +100,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
if route == "/lookup" {
- log.Info("doing lookup len(msg) =", len(msg))
- found, err := lookupRepos(msg)
+ log.Info("doing lookup len(reqPB.Body) =", len(reqPB.Body))
+ found, err := lookupRepos(reqPB.Body)
if err != nil {
return
}
@@ -117,12 +117,12 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
if strings.HasPrefix(route, "/patches/") {
- handlePatches(w, r, msg)
+ handlePatches(w, r, reqPB.Body)
return
}
if route == "/patchset" {
- if err := savePatchset(w, msg); err != nil {
+ if err := savePatchset(w, reqPB.Body); err != nil {
log.Warn("forged /patchset error", err)
return
}
@@ -134,8 +134,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
if route == "/lookup" {
- log.Info("doing lookup len(msg) =", len(msg))
- found, err := lookupRepos(msg)
+ log.Info("doing lookup len(reqPB.Body) =", len(reqPB.Body))
+ found, err := lookupRepos(reqPB.Body)
if err != nil {
return
}
@@ -151,12 +151,12 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
if strings.HasPrefix(route, "/patches/") {
- handlePatches(w, r, msg)
+ handlePatches(w, r, reqPB.Body)
return
}
if route == "/patchset" {
- if err := savePatchset(w, msg); err != nil {
+ if err := savePatchset(w, reqPB.Body); err != nil {
log.Warn("forged /patchset error", err)
return
}
@@ -168,8 +168,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
if route == "/lookup" {
- log.Info("doing lookup len(msg) =", len(msg))
- found, err := lookupRepos(msg)
+ log.Info("doing lookup len(reqPB.Body) =", len(reqPB.Body))
+ found, err := lookupRepos(reqPB.Body)
if err != nil {
return
}
@@ -185,8 +185,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
if route == "/update" {
- log.Info("doing update len(msg) =", len(msg))
- found, err := updateRepos(msg)
+ log.Info("doing update len(reqPB.Body) =", len(reqPB.Body))
+ found, err := updateRepos(reqPB.Body)
if err != nil {
return
}
@@ -208,8 +208,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
/*
start := time.Now()
- log.Info("going to w.Write(msg) with len", len(msg))
- w.Write(msg)
+ log.Info("going to w.Write(reqPB.Body) with len", len(reqPB.Body))
+ w.Write(reqPB.Body)
*/
age := shell.FormatDuration(time.Since(start))
log.Printf("Done with xfer in (%s). happy hacking!\n", age)