forked from appium/appium
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.js
More file actions
23 lines (21 loc) · 735 Bytes
/
middleware.js
File metadata and controls
23 lines (21 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"use strict";
var express = require('express')
, _s = require('underscore.string')
, bodyParser = express.bodyParser();
module.exports.parserWrap = function(req, res, next) {
// wd.js sends us http POSTs with empty body which will make bodyParser fail.
var cLen = req.get('content-length');
if (typeof cLen === "undefined" || parseInt(cLen, 10) <= 0) {
req.headers['content-length'] = 0;
next();
} else {
// allow guineapig
if (!_s.startsWith(req.path, "/test")) {
// hack because python client library sux
if (req.headers['content-type'] === 'application/x-www-form-urlencoded') {
req.headers['content-type'] = 'application/json';
}
}
bodyParser(req, res, next);
}
};