Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'cjthompson-requestInfo'

  • Loading branch information...
commit 41849ff0438a72e01320dbf1544a097036166408 2 parents 358943f + db3ac50
Alex alexadkins authored
Showing with 43 additions and 1 deletion.
  1. +11 −1 app.js
  2. +32 −0 public/javascripts/docs.js
12 app.js
View
@@ -582,7 +582,9 @@ function processRequest(req, res, next) {
};
if (['POST','DELETE','PUT'].indexOf(httpMethod) !== -1) {
- var requestBody = query.stringify(params);
+ var requestBody;
+ requestBody = (options.headers['Content-Type'] === 'application/json') ?
+ JSON.stringify(params) : query.stringify(params);
}
if (apiConfig.oauth) {
@@ -681,6 +683,8 @@ function processRequest(req, res, next) {
}
// Set Headers and Call
+ if (options.headers) req.requestHeaders = options.headers;
+ if (requestBody) req.requestBody = requestBody;
if (response) {
req.resultHeaders = response.headers || 'None';
} else {
@@ -780,6 +784,8 @@ function processRequest(req, res, next) {
next();
} else {
+ if (options.headers) req.requestHeaders = options.headers;
+ if (requestBody) req.requestBody = requestBody;
req.resultHeaders = response.headers;
req.result = JSON.parse(data);
next();
@@ -908,6 +914,8 @@ function processRequest(req, res, next) {
}
// Set Headers and Call
+ if (options.headers) req.requestHeaders = options.headers;
+ if (requestBody) req.requestBody = requestBody;
req.resultHeaders = response.headers;
req.call = url.parse(options.host + options.path);
req.call = url.format(req.call);
@@ -992,6 +1000,8 @@ app.post('/processReq', oauth, processRequest, function(req, res) {
call: req.call,
code: req.res.statusCode
};
+ if (req.requestHeaders) result.requestHeaders = req.requestHeaders;
+ if (req.requestBody) result.requestBody = req.requestBody;
res.send(result);
});
32 public/javascripts/docs.js
View
@@ -227,6 +227,12 @@
resultContainer.append($(document.createElement('h4')).text('Call'));
resultContainer.append($(document.createElement('pre')).addClass('call'));
+ resultContainer.append($(document.createElement('h4')).addClass('reqHeadText').text('Request Headers'));
+ resultContainer.append($(document.createElement('pre')).addClass('requestHeaders'));
+
+ resultContainer.append($(document.createElement('h4')).addClass('reqBodyText').text('Request Body'));
+ resultContainer.append($(document.createElement('pre')).addClass('requestBody'));
+
// Code
resultContainer.append($(document.createElement('h4')).text('Response Code'));
resultContainer.append($(document.createElement('pre')).addClass('code prettyprint'));
@@ -278,6 +284,32 @@
.text(response.call);
}
+ if (response.requestHeaders && !$.isEmptyObject(response.requestHeaders)) {
+ $('pre.requestHeaders', resultContainer)
+ .addClass('prettyprint')
+ .text(formatJSON(response.requestHeaders));
+ } else if ($.isEmptyObject(response.requestHeaders)) {
+ $('pre.requestHeaders', resultContainer).hide();
+ $('h4.reqHeadText').hide();
+ } else {
+ $('pre.requestHeaders', resultContainer).hide();
+ $('h4.reqHeadText').hide();
+ }
+
+
+ if (response.requestBody) {
+ var requestBody;
+ if (response.headers['content-type'].substr(0, 16) === 'application/json') {
+ requestBody = formatJSON(JSON.parse(response.requestBody));
+ } else {
+ requestBody = response.requestBody;
+ }
+ $('pre.requestBody', resultContainer).addClass('prettyprint').text(requestBody);
+ } else {
+ $('pre.requestBody', resultContainer).hide();
+ $('h4.reqBodyText').hide();
+ }
+
if (response.code) {
$('pre.code', resultContainer)
.text(response.code);
Please sign in to comment.
Something went wrong with that request. Please try again.