1
0
Fork 0

Foxx: body and rawBody

This commit is contained in:
Lucas Dohmen 2013-08-08 11:49:41 +02:00
parent f0f95148e0
commit 94c971af9b
3 changed files with 27 additions and 4 deletions

View File

@ -170,6 +170,9 @@ This is the complete path as supplied by the user as a String.
@CLEARPAGE
@copydetails JSF_foxx_BaseMiddleware_request_body
@CLEARPAGE
@copydetails JSF_foxx_BaseMiddleware_request_rawBody
@CLEARPAGE
@copydetails JSF_foxx_BaseMiddleware_request_params

View File

@ -17,9 +17,15 @@ function BaseMiddlewareSpec () {
},
testBodyFunctionAddedToRequest: function () {
request.requestBody = "test";
request.requestBody = JSON.stringify({test: 123});
baseMiddleware(request, response, options, next);
assertEqual(request.body(), "test");
assertEqual(request.body(), {test: 123});
},
testRawBodyFunctionAddedToRequest: function () {
request.requestBody = JSON.stringify({test: 123});
baseMiddleware(request, response, options, next);
assertEqual(request.rawBody(), JSON.stringify({test: 123}));
},
testParamFunctionReturnsUrlParameters: function () {

View File

@ -52,14 +52,28 @@ BaseMiddleware = function () {
////////////////////////////////////////////////////////////////////////////////
/// @fn JSF_foxx_BaseMiddleware_request_body
/// @brief The superfluous `body` function
/// @brief Get the JSON parsed body of the request
///
/// @FUN{request.body()}
///
/// Get the body of the request
/// Get the JSON parsed body of the request if you need the raw version, please
/// refer to the `rawBody` function.
////////////////////////////////////////////////////////////////////////////////
body: function () {
return JSON.parse(this.requestBody);
},
////////////////////////////////////////////////////////////////////////////////
/// @fn JSF_foxx_BaseMiddleware_request_rawBody
/// @brief Get the raw body of the request
///
/// @FUN{request.rawBody()}
///
/// The raw request body, not parsed just a String.
////////////////////////////////////////////////////////////////////////////////
rawBody: function () {
return this.requestBody;
},