Skip to content

Commit

Permalink
Include a text response in /delay
Browse files Browse the repository at this point in the history
  • Loading branch information
sharat87 committed Nov 6, 2024
1 parent 499f24a commit a6a8d56
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func GetRoutes() []Route {

"/b(ase)?64(/(?P<encoded>.*))?": handleDecodeBase64,
"/bytes(/(?P<size>.+))?": handleRandomBytes,
"/delay/(?P<delay>[^/]+)": handleDelayedResponse,
"/drip(-(?P<mode>lines))?(?P<extra>/.*)?": handleDrip,
"/links/(?P<count>\\d+)(/(?P<offset>\\d+))?/?": handleLinks,
"/range/(?P<count>\\d+)/?": handleRange,
Expand All @@ -56,6 +55,8 @@ func GetRoutes() []Route {

`(/(index\.html)?)?`: handleIndex,

"/delay/(?P<delay>[^/]+)": handleDelayedResponse,

"/payload": handlePayload,

"/status/(?P<codes>[\\w,]+)": handleStatus,
Expand Down Expand Up @@ -201,20 +202,19 @@ func handleRandomBytes(ex *exchange.Exchange) {
ex.WriteBytes(util.RandomBytes(n))
}

func handleDelayedResponse(ex *exchange.Exchange) {
func handleDelayedResponse(ex *exchange.Exchange) response.Response {
n, err := strconv.ParseFloat(ex.Field("delay"), 32)

if err != nil {
ex.RespondBadRequest("Invalid delay: " + err.Error())
return
return response.BadRequest("Invalid delay: " + err.Error())
}

if n < 0 || n > 300 {
ex.RespondBadRequest("Delay can't be greater than 300 or less than 0")
return
return response.BadRequest("Delay can't be greater than 300 or less than 0")
}

time.Sleep(time.Duration(n * float64(time.Second)))
return response.New(http.StatusOK, nil, []byte("OK"))
}

func handleDrip(ex *exchange.Exchange) {
Expand Down

0 comments on commit a6a8d56

Please sign in to comment.