Skip to content

Commit

Permalink
Improve docs and error message on /drip
Browse files Browse the repository at this point in the history
  • Loading branch information
sharat87 committed Dec 3, 2023
1 parent c4cdd1f commit 7af403c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ <h3 id=client-tuned-responses>Client Tuned Response <a href="#client-tuned-respo
<dd>Drips data over a duration, with an interval between each piece of data. The piece of data is the <code>*</code>
character. The following query params can be used to configure this endpoint:
<ul>
<li><code>duration</code>: Time seconds over which to periodically drip the data. <em>Default: 2</em>.
<li><code>numbytes</code>: Total number of times to drip the data. <em>Default: 10</em>.
<li><code>duration</code>: Total number of seconds over which to stream the data. <em>Default: 2</em>.
<li><code>numbytes</code>: Total number of bytes to stream. <em>Default: 10</em>.
<li><code>code</code>: The HTTP status code to be used in their response. <em>Default: 200</em>.
<li><code>delay</code>: An initial delay, in seconds. <em>Default: 2</em>.
</ul>
Expand Down
15 changes: 14 additions & 1 deletion routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func GetRoutes() []Route {
"/b(ase)?64(/(?P<encoded>.*))?": handleDecodeBase64,
"/bytes(/(?P<size>.+))?": handleRandomBytes,
"/delay/(?P<delay>[^/]+)": handleDelayedResponse,
"/drip(-(?P<mode>lines))?": handleDrip,
"/drip(-(?P<mode>lines))?(?P<extra>/.*)?": handleDrip,
"/links/(?P<count>\\d+)(/(?P<offset>\\d+))?/?": handleLinks,
"/range/(?P<count>\\d+)/?": handleRange,

Expand Down Expand Up @@ -192,6 +192,19 @@ func handleDelayedResponse(ex *exchange.Exchange) {
func handleDrip(ex *exchange.Exchange) {
// Test with `curl -N localhost:3090/drip`.

extra := ex.Field("extra")
if extra != "" {
// todo: docs duplicated from index.html
ex.RespondBadRequest("Unknown extra path: " + extra +
"\nUse `/drip` or `/drip-lines` with query params:\n" +
" duration: Total number of seconds over which to stream the data. Default: 2.\n" +
" numbytes: Total number of bytes to stream. Default: 10.\n" +
" code: The HTTP status code to be used in their response. Default: 200.\n" +
" delay: An initial delay, in seconds. Default: 2.\n",
)
return
}

writeNewLines := ex.Field("mode") == "lines"

duration, err := ex.QueryParamInt("duration", 2)
Expand Down

0 comments on commit 7af403c

Please sign in to comment.