Skip to content

Commit

Permalink
chore: trying to squeeze some more rps
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Fontes <[email protected]>
  • Loading branch information
lxfontes committed Nov 21, 2024
1 parent 58d4436 commit f97e837
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions wasihttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func newWasiHTTP(vu modules.VU, wm *wrpcMetrics, options clientOptions) (*wasiHT
if err := w.obj.Set("get", w.noBodyRequest(http.MethodGet)); err != nil {
return nil, err
}
if err := w.obj.Set("head", w.noBodyRequest(http.MethodGet)); err != nil {
if err := w.obj.Set("head", w.noBodyRequest(http.MethodHead)); err != nil {
return nil, err
}

Expand Down Expand Up @@ -248,13 +248,15 @@ func (w *wasiHTTP) request(method string, url sobek.Value, args ...sobek.Value)

resp := res.Ok

incomingBody := bytes.NewBuffer(nil)
var incomingBody []byte
if consumeBody {
if _, err := io.Copy(incomingBody, resp.Body); err != nil {
bodyReader := bytes.NewBuffer(incomingBody)
if _, err := io.Copy(bodyReader, resp.Body); err != nil {
return nil, err
}
resp.Body.Close()
incomingBody = bodyReader.Bytes()
}
resp.Body.Close()

reqDuration := time.Since(reqStart)
measurements = append(measurements, w.metrics.sample(w.metrics.httpDuration, metrics.D(reqDuration), tagSet))
Expand All @@ -278,7 +280,7 @@ func (w *wasiHTTP) request(method string, url sobek.Value, args ...sobek.Value)
return &httpResponse{
Status: int(resp.Status),
Headers: incomingHeaders,
Body: incomingBody.Bytes(),
Body: incomingBody,
}, nil
}

Expand Down

0 comments on commit f97e837

Please sign in to comment.