Troubles flexing fake server responses based on parameters specified in the request body.

80 views
Skip to first unread message

Fred Eckertson

unread,
Apr 19, 2013, 6:01:44 PM4/19/13
to sin...@googlegroups.com
We would like the fake server to flex the returned response based on parameters specified in the request body in addition to the url even for (especially for) GET transactions. Unfortunately, the send function only copies data into the requestBody of the fake request if {code} !/^(get|head)$/i.test(this.method) {code}. Moving the requestBody set statement out of that branch, allowed us to proceed as desired. Is there a specific motivation for not always setting the requestBody equal to data?

We had some trouble figuring out how to make the fake server flex its reply as indicated in the documentation ("When the response is a function..."). We eventually found the solution by looking at the "responds to request from function handler" test in fake_server_tests.js. Adding a similar example to the documentation might save others from having the same struggles.

thanks,
fred.

PS -
Sinon is really great.

Christian Johansen

unread,
Apr 20, 2013, 2:27:40 PM4/20/13
to sin...@googlegroups.com
> We would like the fake server to flex the returned response based on
> parameters specified in the request body in addition to the url even for
> (especially for) GET transactions. Unfortunately, the send function only
> copies data into the requestBody of the fake request if
> {code} !/^(get|head)$/i.test(this.method) {code}. Moving the requestBody
> set statement out of that branch, allowed us to proceed as desired. Is
> there a specific motivation for not always setting the requestBody equal to
> data?

As far as I know, this is how HTTP works. There's no requestBody with a
GET request - the parameters are part of the URL.

> We had some trouble figuring out how to make the fake server flex its reply
> as indicated in the documentation ("When the response is a function...").
> We eventually found the solution by looking at the "responds to request
> from function handler" test in fake_server_tests.js. Adding a similar
> example to the documentation might save others from having the same
> struggles.

I gladly accept pull requests for http://github.com/cjohansen/sinon-web :)

Christian
Reply all
Reply to author
Forward
0 new messages