New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

http4js

Package Overview
Dependencies
Maintainers
1
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http4js - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

1

dist/main/core/RoutingHttpHandler.d.ts

@@ -23,3 +23,4 @@ import { Response } from "./Response";

match(request: Http4jsRequest): Response;
private defaultNotFoundHandler;
private createInMemResponse(chunks, method, url, headers);
}

10

dist/main/core/RoutingHttpHandler.js

@@ -24,2 +24,7 @@ "use strict";

this.filters = [];
this.defaultNotFoundHandler = function (request) {
var notFoundBody = request.method + " to " + request.uri.template + " did not match routes";
var body = new Body_1.Body(notFoundBody);
return new Response_1.Response(404, body);
};
this.path = path;

@@ -86,5 +91,4 @@ this.handlers[path] = { verb: method, handler: handler };

else {
var notFoundBody = request.method + " to " + request.uri.template + " did not match routes " + paths.join(" // ");
var body = new Body_1.Body(notFoundBody);
return new Response_1.Response(404, body);
var filtered = this.filters.reduce(function (acc, next) { return next(acc); }, this.defaultNotFoundHandler);
return filtered(request);
}

@@ -91,0 +95,0 @@ };

@@ -100,2 +100,28 @@ "use strict";

});
it("custom 404s using filters", function () {
var response = RoutingHttpHandler_1.getTo("/", function () {
return new Response_1.Response(200, new Body_1.Body("hello, world!"));
}).withFilter(function (handler) { return function (req) {
if (handler(req).status == 404) {
return new Response_1.Response(404, new Body_1.Body("Page not found"));
}
else {
handler(req);
}
}; })
.match(new Request_1.Request("GET", "/unknown"));
assert_1.equal(response.status, 404);
assert_1.equal(response.bodyString(), "Page not found");
});
it("ordering - filters apply in order they are declared", function () {
var response = RoutingHttpHandler_1.getTo("/", function () {
return new Response_1.Response(200, new Body_1.Body("hello, world!"));
}).withFilter(function (handler) { return function (req) {
return handler(req).replaceHeader("person", "tosh");
}; }).withFilter(function (handler) { return function (req) {
return handler(req).replaceHeader("person", "bosh");
}; })
.match(new Request_1.Request("GET", "/"));
assert_1.equal(response.getHeader("person"), "bosh");
});
});
{
"name": "http4js",
"version": "1.0.6",
"version": "1.0.7",
"description": "A lightweight HTTP toolkit",

@@ -8,3 +8,3 @@ "main": "dist/index.js",

"scripts": {
"test": "mocha src/test/**",
"test": "tsc; mocha dist/test/**",
"build": "tsc",

@@ -11,0 +11,0 @@ "prepublishOnly": "tsc -p ./ --outDir dist/",

@@ -26,7 +26,5 @@ ## Http4js

- code:
- daves advice
- extract form data
- ordering of filters
- other client verbs
- daves advice
- extract form data
- other client verbs
- write docs

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc