This commit is contained in:
Zheng Kai
2023-03-31 10:12:18 +08:00
parent af429a393a
commit 8e72c62281
17 changed files with 229 additions and 61 deletions

View File

@@ -8,12 +8,38 @@ import (
"project/zj"
)
func (c *Core) getAB(p *pb.Req, r *http.Request) (ab []byte, cached bool, err error) {
ab, ok := tryCache(p)
if ok {
cached = true
return
}
pr := c.add(p, r)
go func() {
reqFile := util.CacheName(p.Hash()) + `-req.json`
if !util.FileExists(reqFile) {
util.WriteFile(reqFile, p.Body)
}
}()
pr.wait()
ab = pr.rsp
err = pr.err
return
}
func req(w http.ResponseWriter, r *http.Request) (p *pb.Req, err error) {
path := r.URL.Path
method := r.Method
zj.J(method, path)
if path == `/favicon.ico` {
err = errSkip
return
}
ab, err := io.ReadAll(http.MaxBytesReader(w, r.Body, 1024*1024))
if err != nil {