Skip to content

Commit

Permalink
Optimize argument handling in typeofrequest function
Browse files Browse the repository at this point in the history
- Streamlined the parsing of multiple content type arguments for improved readability.
- Simplified the logic for handling flattened arguments while maintaining existing functionality.
- Ensured consistent behavior for checking request body presence and validating content types.
  • Loading branch information
Ayoub-Mabrouk committed Nov 11, 2024
1 parent 0d79e2d commit 0517f1b
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,27 +116,19 @@ function hasbody (req) {
*
* this.is('html'); // => false
*
* @param {String|Array} types...
* @return {String|false|null}
* @param {Object} req
* @param {(String|Array)} types...
* @return {(String|false|null)}
* @public
*/

function typeofrequest (req, types_) {
var types = types_

// no body
if (!hasbody(req)) {
return null
}

if (!hasbody(req)) return null
// support flattened arguments
if (arguments.length > 2) {
types = new Array(arguments.length - 1)
for (var i = 0; i < types.length; i++) {
types[i] = arguments[i + 1]
}
}

var types = arguments.length > 2
? Array.prototype.slice.call(arguments, 1)
: types_
// request content type
var value = req.headers['content-type']

Expand Down

0 comments on commit 0517f1b

Please sign in to comment.