mirror of
https://github.com/openziti/zrok.git
synced 2025-06-18 07:46:45 +02:00
min/max payload sizes (#40)
This commit is contained in:
parent
0a3dafbdb4
commit
eb51705e55
@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/rand"
|
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
httptransport "github.com/go-openapi/runtime/client"
|
httptransport "github.com/go-openapi/runtime/client"
|
||||||
@ -16,6 +15,7 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"io"
|
"io"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -31,6 +31,8 @@ type run struct {
|
|||||||
statusEvery int
|
statusEvery int
|
||||||
dwellSeconds int
|
dwellSeconds int
|
||||||
timeoutSeconds int
|
timeoutSeconds int
|
||||||
|
minPayload int
|
||||||
|
maxPayload int
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRun() *run {
|
func newRun() *run {
|
||||||
@ -46,6 +48,8 @@ func newRun() *run {
|
|||||||
cmd.Flags().IntVarP(&r.statusEvery, "status-every", "E", 100, "Show status every # iterations")
|
cmd.Flags().IntVarP(&r.statusEvery, "status-every", "E", 100, "Show status every # iterations")
|
||||||
cmd.Flags().IntVarP(&r.dwellSeconds, "dwell-seconds", "D", 1, "Dwell # seconds before starting iterations")
|
cmd.Flags().IntVarP(&r.dwellSeconds, "dwell-seconds", "D", 1, "Dwell # seconds before starting iterations")
|
||||||
cmd.Flags().IntVarP(&r.timeoutSeconds, "timeout-seconds", "T", 30, "Time out after # seconds when sending http requests")
|
cmd.Flags().IntVarP(&r.timeoutSeconds, "timeout-seconds", "T", 30, "Time out after # seconds when sending http requests")
|
||||||
|
cmd.Flags().IntVar(&r.minPayload, "min-payload", 64, "Minimum payload size in bytes")
|
||||||
|
cmd.Flags().IntVar(&r.maxPayload, "max-payload", 10240, "Maximum payload size in bytes")
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +121,11 @@ func (l *looper) run() {
|
|||||||
if i > 0 && i%l.r.statusEvery == 0 {
|
if i > 0 && i%l.r.statusEvery == 0 {
|
||||||
logrus.Infof("looper #%d: iteration #%d", l.id, i)
|
logrus.Infof("looper #%d: iteration #%d", l.id, i)
|
||||||
}
|
}
|
||||||
outpayload := make([]byte, 10240)
|
sz := l.r.maxPayload
|
||||||
|
if l.r.maxPayload-l.r.minPayload > 0 {
|
||||||
|
sz = rand.Intn(l.r.maxPayload-l.r.minPayload) + l.r.minPayload
|
||||||
|
}
|
||||||
|
outpayload := make([]byte, sz)
|
||||||
outbase64 := base64.StdEncoding.EncodeToString(outpayload)
|
outbase64 := base64.StdEncoding.EncodeToString(outpayload)
|
||||||
rand.Read(outpayload)
|
rand.Read(outpayload)
|
||||||
if req, err := http.NewRequest("POST", tunnelResp.Payload.ProxyEndpoint, bytes.NewBufferString(outbase64)); err == nil {
|
if req, err := http.NewRequest("POST", tunnelResp.Payload.ProxyEndpoint, bytes.NewBufferString(outbase64)); err == nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user