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.2.1 to 1.2.2

.idea/dbnavigator.xml

15

dist/main/core/Request.js

@@ -14,3 +14,3 @@ "use strict";

this.form = {};
this.method = method;
this.method = method.toUpperCase();
if (typeof uri == "string") {

@@ -53,13 +53,14 @@ this.uri = Uri_1.Uri.of(uri);

Request.prototype.getHeader = function (name) {
return this.headers[name];
return this.headers[name.toLowerCase()];
};
Request.prototype.setHeader = function (name, value) {
if (this.headers[name] == null) {
this.headers[name] = value;
var caseInsensitiveName = name.toLowerCase();
if (this.headers[caseInsensitiveName] == null) {
this.headers[caseInsensitiveName] = value;
}
else if (typeof this.headers[name] == "string") {
this.headers[name] = [this.headers[name], value];
else if (typeof this.headers[caseInsensitiveName] == "string") {
this.headers[caseInsensitiveName] = [this.headers[caseInsensitiveName], value];
}
else {
this.headers[name].push(value);
this.headers[caseInsensitiveName].push(value);
}

@@ -66,0 +67,0 @@ return this;

@@ -59,5 +59,5 @@ "use strict";

if (status === void 0) { status = 200; }
if (body === void 0) { body = new Body_1.Body(""); }
if (body === void 0) { body = ""; }
return new Response(status, body);
}
exports.response = response;
import { Response } from "./Response";
import { HttpHandler } from "./HttpMessage";
import { Request } from "./Request";
import { Http4jsServer } from "./Server";
import { Http4jsServer, Server } from "./Server";
import { Filter } from "./Filters";
export interface RoutingHttpHandler {
withFilter(filter: (HttpHandler) => HttpHandler): RoutingHttpHandler;
asServer(port: number): Http4jsServer;
asServer(server: Server): Http4jsServer;
match(request: Request): Promise<Response>;

@@ -20,6 +20,5 @@ }

withHandler(path: string, method: string, handler: HttpHandler): ResourceRoutingHttpHandler;
asServer(port: number): Http4jsServer;
asServer(server: Http4jsServer): Http4jsServer;
match(request: Request): Promise<Response>;
private defaultNotFoundHandler;
private createInMemResponse(chunks, method, url, headers);
}

@@ -26,0 +25,0 @@ export declare function routes(method: string, path: string, handler: HttpHandler): ResourceRoutingHttpHandler;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Response_1 = require("./Response");
var Request_1 = require("./Request");
var Body_1 = require("./Body");
var Server_1 = require("./Server");
var Uri_1 = require("./Uri");

@@ -34,20 +32,5 @@ var ResourceRoutingHttpHandler = (function () {

};
ResourceRoutingHttpHandler.prototype.asServer = function (port) {
var _this = this;
this.server = new Server_1.Server(port);
this.server.server.on("request", function (req, res) {
var headers = req.headers, method = req.method, url = req.url;
var chunks = [];
req.on('error', function (err) {
console.error(err);
}).on('data', function (chunk) {
chunks.push(chunk);
}).on('end', function () {
var response = _this.createInMemResponse(chunks, method, url, headers);
response.then(function (response) {
res.writeHead(response.status, response.headers);
res.end(response.body.bytes);
});
});
});
ResourceRoutingHttpHandler.prototype.asServer = function (server) {
this.server = server;
server.registerCatchAllHandler(this);
return this.server;

@@ -78,7 +61,2 @@ };

};
ResourceRoutingHttpHandler.prototype.createInMemResponse = function (chunks, method, url, headers) {
var body = new Body_1.Body(Buffer.concat(chunks));
var inMemRequest = new Request_1.Request(method, url, body, headers);
return this.match(inMemRequest);
};
return ResourceRoutingHttpHandler;

@@ -85,0 +63,0 @@ }());

@@ -0,13 +1,28 @@

import { RoutingHttpHandler } from "./RoutingHttpHandler";
export interface Http4jsServer {
server: any;
port: number;
registerCatchAllHandler(routing: RoutingHttpHandler): void;
start(): void;
stop(): void;
}
export declare class ExpressServer implements Http4jsServer {
server: any;
port: number;
private routing;
constructor(expressApp: any, port: number);
registerCatchAllHandler(routing: RoutingHttpHandler): void;
private createInMemResponse(chunks, method, url, headers);
start(): void;
stop(): void;
}
export declare class Server implements Http4jsServer {
server: any;
port: number;
routing: RoutingHttpHandler;
constructor(port: number);
registerCatchAllHandler(routing: RoutingHttpHandler): void;
start(): void;
stop(): void;
private createInMemResponse(chunks, method, url, headers);
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var http = require("http");
var Request_1 = require("./Request");
var Body_1 = require("./Body");
var ExpressServer = (function () {
function ExpressServer(expressApp, port) {
this.port = port;
this.server = expressApp;
return this;
}
ExpressServer.prototype.registerCatchAllHandler = function (routing) {
var _this = this;
this.routing = routing;
this.server.use(function (req, res, next) {
var headers = req.headers, method = req.method, url = req.url;
var body = Object.keys(req.body).length == 0 ? [] : req.body;
if (headers['content-type'] == 'application/json')
body = [Buffer.from(JSON.stringify(body))];
var response = _this.createInMemResponse(body, method, url, headers);
response.then(function (response) {
Object.keys(response.headers).forEach(function (header) { return res.setHeader(header, response.headers[header]); });
res.end(response.body.bytes);
});
next();
});
};
ExpressServer.prototype.createInMemResponse = function (chunks, method, url, headers) {
var body = new Body_1.Body(Buffer.concat(chunks));
var inMemRequest = new Request_1.Request(method, url, body, headers);
return this.routing.match(inMemRequest);
};
ExpressServer.prototype.start = function () {
this.server.listen(this.port);
};
ExpressServer.prototype.stop = function () {
console.log("cannot stop an express server ... lol");
};
return ExpressServer;
}());
exports.ExpressServer = ExpressServer;
var Server = (function () {

@@ -10,2 +48,21 @@ function Server(port) {

}
Server.prototype.registerCatchAllHandler = function (routing) {
var _this = this;
this.routing = routing;
this.server.on("request", function (req, res) {
var headers = req.headers, method = req.method, url = req.url;
var chunks = [];
req.on('error', function (err) {
console.error(err);
}).on('data', function (chunk) {
chunks.push(chunk);
}).on('end', function () {
var response = _this.createInMemResponse(chunks, method, url, headers);
response.then(function (response) {
res.writeHead(response.status, response.headers);
res.end(response.body.bytes);
});
});
});
};
Server.prototype.start = function () {

@@ -17,4 +74,9 @@ this.server.listen(this.port);

};
Server.prototype.createInMemResponse = function (chunks, method, url, headers) {
var body = new Body_1.Body(Buffer.concat(chunks));
var inMemRequest = new Request_1.Request(method, url, body, headers);
return this.routing.match(inMemRequest);
};
return Server;
}());
exports.Server = Server;

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

describe("in mem request", function () {
it("set method is case insensitive", function () {
assert_1.equal(new Request_1.Request("gEt", "/")
.method, "GET");
});
it("set uri", function () {

@@ -31,2 +35,7 @@ assert_1.equal(new Request_1.Request("GET", "/")

});
it("get header is case insensitive", function () {
assert_1.equal(new Request_1.Request("GET", "some/url")
.setHeader("TOM", "rocks")
.getHeader("tom"), "rocks");
});
it("set header on request", function () {

@@ -33,0 +42,0 @@ assert_1.equal(new Request_1.Request("GET", "some/url")

@@ -0,1 +1,3 @@

import {HttpClient} from "./src/main/core/Client";
import {request} from "./src/main/core/Request";
export * from "./dist/main/core/RoutingHttpHandler";

@@ -8,1 +10,20 @@ export * from "./dist/main/core/Request";

export * from "./dist/main/core/Uri";
const express = require('express');
const bodyParser = require('body-parser');
let expressApp = express();
expressApp.use(bodyParser.urlencoded({extended: true}));
expressApp.use(bodyParser.json());
expressApp.post("/express-post", (req, res) => {
console.log("REQ BODY EXPRESS");
console.log(req.body);
res.end("OK");
});
expressApp.listen(3000);
HttpClient(request("POST", "http://localhost:3000/express-post", '{"a": "b"}', {"Content-Type": "application/json"})).then(
response => console.log(response.bodyString())
);
{
"name": "http4js",
"version": "1.2.1",
"version": "1.2.2",
"description": "A lightweight HTTP toolkit",

@@ -24,4 +24,5 @@ "main": "dist/index.js",

"devDependencies": {
"@types/mocha": "2.2.47",
"@types/node": "9.4.0",
"@types/mocha": "2.2.47",
"body-parser": "1.18.2",
"mocha": "5.0.0",

@@ -28,0 +29,0 @@ "ts-node": "4.1.0",

@@ -38,6 +38,6 @@ ## http4js

- support express, koa backends
- complete http4js-eg
- document unit testing routing and fakes
- document a proxy
- document unit testing routing and fakes
- complete http4js-eg
- support express, koa backends

@@ -44,0 +44,0 @@ #### Example

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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