Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dkx/http-server

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dkx/http-server - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

1

lib/testing/middleware.d.ts

@@ -11,3 +11,4 @@ /// <reference types="node" />

state?: RequestState;
onBodyWrite?: (chunk: any) => void;
}
export declare function testMiddleware(middleware: Middleware, options?: MiddlewareTestOptions): Promise<Response>;

34

lib/testing/middleware.js

@@ -15,16 +15,26 @@ "use strict";

function testMiddleware(middleware, options = {}) {
let body;
if (typeof options.body !== 'undefined') {
body = new stream_1.Readable;
body._read = () => {
body.push(new Buffer(options.body));
body.push(null);
};
}
const req = new request_1.Request(options.method, options.url, options.headers, body);
const res = new response_1.Response(new response_1.ResponseBodyBag);
const state = typeof options.state === 'undefined' ? {} : options.state;
return middleware(req, res, (res) => __awaiter(this, void 0, void 0, function* () { return res; }), state);
return __awaiter(this, void 0, void 0, function* () {
let body;
if (typeof options.body !== 'undefined') {
body = new stream_1.Readable;
body._read = () => {
body.push(new Buffer(options.body));
body.push(null);
};
}
const state = typeof options.state === 'undefined' ? {} : options.state;
const bodyBag = new response_1.ResponseBodyBag;
const req = new request_1.Request(options.method, options.url, options.headers, body);
const res = yield middleware(req, new response_1.Response(bodyBag), (res) => __awaiter(this, void 0, void 0, function* () { return res; }), state);
if (typeof options.onBodyWrite !== 'undefined') {
const body = new response_1.ResponseBody((chunk, encoding, done) => {
options.onBodyWrite(chunk);
done();
});
bodyBag.attachBody(body);
}
return res;
});
}
exports.testMiddleware = testMiddleware;
//# sourceMappingURL=middleware.js.map
{
"name": "@dkx/http-server",
"version": "1.0.0",
"version": "1.1.0",
"description": "Minimalistic HTTP server",

@@ -5,0 +5,0 @@ "repository": "git@gitlab.com:dkx/http/server.git",

@@ -91,2 +91,3 @@ # DKX/Http/Server

{
response.write('hello world');
response = response.withHeader('X-Middleware-header', 'lorem ipsum');

@@ -96,2 +97,3 @@ return next(response);

const data = [];
const response = await testMiddleware(myUselessMiddleware, {

@@ -106,2 +108,5 @@ method: 'POST',

msg: 'My custom shared state'
},
onBodyWrite: function(chunk) {
data.push(chunk.toString());
}

@@ -111,2 +116,3 @@ });

console.log(response.getHeader('X-Middleware-header')); // output: "lorem ipsum"
console.log(data); // output: ["hello world"]
```

@@ -113,0 +119,0 @@

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