aboutsummaryrefslogtreecommitdiff
path: root/http_server.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-09-28 15:36:05 +0700
committerShulhan <ms@kilabit.info>2023-09-28 17:31:58 +0700
commit6cb1e0f2263a528b29889743290e15258353087f (patch)
tree8afe3742e385ee05260bb546194f28bcf29a3c56 /http_server.go
parent3cfb38dd0f7a793f27ca6d348316e53ae9ec7105 (diff)
downloadawwan-6cb1e0f2263a528b29889743290e15258353087f.tar.xz
all: move field bufout and buferr out of httpServer struct
Those fields are used on each HTTP request to /awwan/api/execute, which make them not safe if two or more requests processed at the same time.
Diffstat (limited to 'http_server.go')
-rw-r--r--http_server.go18
1 files changed, 8 insertions, 10 deletions
diff --git a/http_server.go b/http_server.go
index ab98992..1ede15b 100644
--- a/http_server.go
+++ b/http_server.go
@@ -13,7 +13,6 @@ import (
"path/filepath"
"strings"
- libbytes "github.com/shuLhan/share/lib/bytes"
libhttp "github.com/shuLhan/share/lib/http"
"github.com/shuLhan/share/lib/memfs"
@@ -37,9 +36,6 @@ type httpServer struct {
memfsBase *memfs.MemFS // The files caches.
baseDir string
-
- bufout bytes.Buffer
- buferr bytes.Buffer
}
// newHttpServer create and initialize HTTP server to serve awwan HTTP API
@@ -407,11 +403,13 @@ func (httpd *httpServer) awwanApiExecute(epr *libhttp.EndpointRequest) (resb []b
req.Script = filepath.Join(httpd.memfsBase.Opts.Root, req.Script)
req.lineRange = parseLineRange(req.LineRange)
- httpd.bufout.Reset()
- httpd.buferr.Reset()
+ var (
+ bufout bytes.Buffer
+ buferr bytes.Buffer
+ )
- req.stdout = &httpd.bufout
- req.stderr = &httpd.buferr
+ req.stdout = &bufout
+ req.stderr = &buferr
if req.Mode == CommandModeLocal {
err = httpd.aww.Local(req)
@@ -425,8 +423,8 @@ func (httpd *httpServer) awwanApiExecute(epr *libhttp.EndpointRequest) (resb []b
data = &HttpResponse{
Request: req,
- Stdout: libbytes.Copy(httpd.bufout.Bytes()),
- Stderr: libbytes.Copy(httpd.buferr.Bytes()),
+ Stdout: bufout.Bytes(),
+ Stderr: buferr.Bytes(),
}
res.Code = http.StatusOK