This commit is contained in:
Zheng Kai
2023-03-30 10:07:57 +08:00
parent 1b107ed035
commit 049277f1f6
19 changed files with 889 additions and 20 deletions

43
server/src/core/req.go Normal file
View File

@@ -0,0 +1,43 @@
package core
import (
"crypto/md5"
"io/ioutil"
"net/http"
"project/pb"
"project/util"
"google.golang.org/protobuf/proto"
)
func req(w http.ResponseWriter, r *http.Request) (p *pb.Req, hash [16]byte, err error) {
path := r.URL.Path
method := r.Method
ab, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, 1024*1024))
if err != nil {
return
}
go util.WriteFile(`last-req.json`, ab)
p = &pb.Req{
Path: path,
Method: method,
Body: ab,
}
pab, err := proto.Marshal(p)
if err != nil {
err500(w)
return
}
hash = md5.Sum(pab)
return
}
func err500(w http.ResponseWriter) {
w.WriteHeader(http.StatusInternalServerError)
}