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

@adonisjs/http-server

Package Overview
Dependencies
Maintainers
2
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@adonisjs/http-server - npm Package Compare versions

Comparing version 3.0.3 to 4.0.0

6

build/adonis-typings/context.d.ts

@@ -17,5 +17,4 @@ /**

import { ResponseContract } from '@ioc:Adonis/Core/Response';
import { ServerConfig } from '@ioc:Adonis/Core/Server';
import { ProfilerRowContract } from '@ioc:Adonis/Core/Profiler';
import { EncryptionContract } from '@ioc:Adonis/Core/Encryption';
import { ApplicationContract } from '@ioc:Adonis/Core/Application';
/**

@@ -45,6 +44,7 @@ * Http request context passed to all middleware

export interface HttpContextConstructorContract extends MacroableConstructorContract<HttpContextContract> {
app?: ApplicationContract;
/**
* Creates a new fake context instance for a given route.
*/
create(routePattern: string, routeParams: any, logger: LoggerContract, profiler: ProfilerRowContract, encryption: EncryptionContract, req?: IncomingMessage, res?: ServerResponse, serverConfig?: ServerConfig): HttpContextContract;
create(routePattern: string, routeParams: any, req?: IncomingMessage, res?: ServerResponse): HttpContextContract;
new (request: RequestContract, response: ResponseContract, logger: LoggerContract, profiler: ProfilerRowContract): HttpContextContract;

@@ -51,0 +51,0 @@ }

@@ -59,2 +59,6 @@ /**

/**
* Update route params
*/
updateParams(body: any): void;
/**
* Update the query string with the new data object. The `all` property

@@ -61,0 +65,0 @@ * will be re-computed by merging the query and the request body.

@@ -375,2 +375,7 @@ /**

/**
* Clear existing query string values added using
* "withQs"
*/
clearQs(): this;
/**
* Forward the current QueryString or define one.

@@ -377,0 +382,0 @@ */

@@ -39,3 +39,5 @@ "use strict";

this.container.bind('Adonis/Core/HttpContext', () => {
return require('../src/HttpContext').HttpContext;
const { HttpContext } = require('../src/HttpContext');
HttpContext.app = this.container.use('Adonis/Core/Application');
return HttpContext;
});

@@ -42,0 +44,0 @@ }

@@ -11,3 +11,3 @@ /**

/**
* Cookie parser parses the HTTP `cookie` method and collects all cookies
* Cookie parser parses the HTTP `cookie` header and collects all cookies
* inside an object of `key-value` pair, but doesn't attempt to decrypt

@@ -14,0 +14,0 @@ * or unsign or decode the individual values.

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

var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);

@@ -40,3 +40,3 @@ return result;

/**
* Cookie parser parses the HTTP `cookie` method and collects all cookies
* Cookie parser parses the HTTP `cookie` header and collects all cookies
* inside an object of `key-value` pair, but doesn't attempt to decrypt

@@ -43,0 +43,0 @@ * or unsign or decode the individual values.

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

var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);

@@ -28,0 +28,0 @@ return result;

@@ -12,4 +12,3 @@ /**

import { Macroable } from 'macroable';
import { RouteNode, RouterContract } from '@ioc:Adonis/Core/Route';
import { ServerConfig } from '@ioc:Adonis/Core/Server';
import { RouteNode } from '@ioc:Adonis/Core/Route';
import { IncomingMessage, ServerResponse } from 'http';

@@ -20,3 +19,3 @@ import { LoggerContract } from '@ioc:Adonis/Core/Logger';

import { ProfilerRowContract } from '@ioc:Adonis/Core/Profiler';
import { EncryptionContract } from '@ioc:Adonis/Core/Encryption';
import { ApplicationContract } from '@ioc:Adonis/Core/Application';
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';

@@ -32,5 +31,22 @@ /**

profiler: ProfilerRowContract;
/**
* Set inside the provider
*/
static app: ApplicationContract;
/**
* A unique key for the current route
*/
routeKey: string;
/**
* Route params
*/
params: any;
/**
* Route subdomains
*/
subdomains: any;
/**
* Reference to the current route. Not available inside
* server hooks
*/
route?: RouteNode;

@@ -48,5 +64,7 @@ /**

/**
* Creates a new fake context instance for a given route.
* Creates a new fake context instance for a given route. The method is
* meant to be used inside an AdonisJS application since it relies
* directly on the IoC container.
*/
static create(routePattern: string, routeParams: any, logger: LoggerContract, profiler: ProfilerRowContract, encryption: EncryptionContract, router: RouterContract, req?: IncomingMessage, res?: ServerResponse, serverConfig?: ServerConfig): HttpContext;
static create(routePattern: string, routeParams: any, req?: IncomingMessage, res?: ServerResponse): HttpContext;
}

@@ -10,5 +10,2 @@ "use strict";

*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -19,3 +16,2 @@ exports.HttpContext = void 0;

const util_1 = require("util");
const proxy_addr_1 = __importDefault(require("proxy-addr"));
const macroable_1 = require("macroable");

@@ -37,3 +33,9 @@ const http_1 = require("http");

this.profiler = profiler;
/**
* Route params
*/
this.params = {};
/**
* Route subdomains
*/
this.subdomains = {};

@@ -56,21 +58,15 @@ /*

/**
* Creates a new fake context instance for a given route.
* Creates a new fake context instance for a given route. The method is
* meant to be used inside an AdonisJS application since it relies
* directly on the IoC container.
*/
static create(routePattern, routeParams, logger, profiler, encryption, router, req, res, serverConfig) {
static create(routePattern, routeParams, req, res) {
const Logger = HttpContext.app.container.use('Adonis/Core/Logger');
const Router = HttpContext.app.container.use('Adonis/Core/Route');
const Profiler = HttpContext.app.container.use('Adonis/Core/Profiler');
const Encryption = HttpContext.app.container.use('Adonis/Core/Encryption');
const serverConfig = HttpContext.app.container.use('Adonis/Core/Config').get('app.http', {});
req = req || new http_1.IncomingMessage(new net_1.Socket());
res = res || new http_1.ServerResponse(req);
/*
* Composing server config
*/
serverConfig = Object.assign({
secret: Math.random().toFixed(36).substring(2, 38),
subdomainOffset: 2,
allowMethodSpoofing: true,
etag: false,
generateRequestId: false,
cookie: {},
jsonpCallbackName: 'callback',
trustProxy: proxy_addr_1.default.compile('loopback'),
}, serverConfig || {});
/*
* Creating the url from the router pattern and params. Only

@@ -83,3 +79,3 @@ * when actual URL isn't defined.

*/
const request = new Request_1.Request(req, res, encryption, {
const request = new Request_1.Request(req, res, Encryption, {
allowMethodSpoofing: serverConfig.allowMethodSpoofing,

@@ -93,11 +89,11 @@ subdomainOffset: serverConfig.subdomainOffset,

*/
const response = new Response_1.Response(req, res, encryption, {
const response = new Response_1.Response(req, res, Encryption, {
etag: serverConfig.etag,
cookie: serverConfig.cookie,
jsonpCallbackName: serverConfig.jsonpCallbackName,
}, router);
}, Router);
/*
* Creating new ctx instance
*/
const ctx = new HttpContext(request, response, logger, profiler);
const ctx = new HttpContext(request, response, Logger, Profiler);
/*

@@ -104,0 +100,0 @@ * Attaching route to the ctx

@@ -39,4 +39,11 @@ /**

/**
* Forward the current QueryString or define one.
* Clearing query string values added using the
* "withQs" method
*/
clearQs(): this;
/**
* Define query string for the redirect. Not passing
* any value will forward the current request query
* string.
*/
withQs(): this;

@@ -43,0 +50,0 @@ withQs(values: {

@@ -16,4 +16,4 @@ "use strict";

/// <reference path="../../adonis-typings/index.ts" />
const qs_1 = __importDefault(require("qs"));
const url_1 = require("url");
const qs_1 = require("qs");
const encodeurl_1 = __importDefault(require("encodeurl"));

@@ -49,2 +49,11 @@ const RouterException_1 = require("../Exceptions/RouterException");

}
/**
* Clearing query string values added using the
* "withQs" method
*/
clearQs() {
this.forwardQueryString = false;
this.queryString = {};
return this;
}
withQs(name, value) {

@@ -59,3 +68,3 @@ if (typeof name === 'undefined') {

}
this.queryString = name;
Object.assign(this.queryString, name);
return this;

@@ -88,13 +97,18 @@ }

toPath(url) {
let query;
// Extract the current QueryString if we want to forward it.
let query = {};
/**
* Extract the current query string
*/
if (this.forwardQueryString) {
const { query: extractedQuery } = url_1.parse(this.request.url, false);
query = extractedQuery;
query = qs_1.default.parse(url_1.parse(this.request.url, false).query || '');
}
// If we define our own QueryString, use it instead of the one forwarded.
if (Object.keys(this.queryString).length > 0) {
query = qs_1.stringify(this.queryString);
}
url = query ? `${url}?${query}` : url;
/**
* Assign custom query string
*/
Object.assign(query, this.queryString);
/**
* Convert string
*/
const stringified = qs_1.default.stringify(query);
url = stringified ? `${url}?${stringified}` : url;
this.response.location(encodeurl_1.default(url));

@@ -101,0 +115,0 @@ this.response.safeStatus(this.statusCode);

@@ -36,2 +36,6 @@ /**

/**
* Route params
*/
private routeParams;
/**
* A merged copy of `request body` and `querystring`

@@ -124,2 +128,12 @@ */

/**
* Update route params
*/
updateParams(data: object): void;
/**
* Returns route params
*/
params(): {
[key: string]: any;
};
/**
* Returns reference to the query string object

@@ -171,2 +185,14 @@ */

/**
* Returns value for a given key from route params
*
* @example
* ```js
* request.param('id')
*
* // with default value
* request.param('id', 1)
* ```
*/
param(key: string, defaultValue?: any): any;
/**
* Get everything from the request body except the given keys.

@@ -173,0 +199,0 @@ *

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

/**
* Route params
*/
this.routeParams = {};
/**
* A merged copy of `request body` and `querystring`

@@ -159,2 +163,14 @@ */

/**
* Update route params
*/
updateParams(data) {
this.routeParams = data;
}
/**
* Returns route params
*/
params() {
return this.routeParams;
}
/**
* Returns reference to the query string object

@@ -210,2 +226,16 @@ */

/**
* Returns value for a given key from route params
*
* @example
* ```js
* request.param('id')
*
* // with default value
* request.param('id', 1)
* ```
*/
param(key, defaultValue) {
return utils_1.lodash.get(this.routeParams, key, defaultValue);
}
/**
* Get everything from the request body except the given keys.

@@ -212,0 +242,0 @@ *

@@ -32,2 +32,5 @@ /**

private writerMethod;
/**
* Cookies serializer
*/
private cookieSerializer;

@@ -34,0 +37,0 @@ /**

@@ -56,2 +56,5 @@ "use strict";

this.writerMethod = 'endResponse';
/**
* Cookies serializer
*/
this.cookieSerializer = new Serializer_1.CookieSerializer(this.encryption);

@@ -75,3 +78,3 @@ /**

get finished() {
return this.response.finished;
return this.response.writableFinished;
}

@@ -120,12 +123,12 @@ /**

getDataType(content) {
const dataType = typeof content;
if (Buffer.isBuffer(content)) {
return 'buffer';
}
if (content instanceof Date) {
return 'date';
}
const dataType = typeof content;
if (dataType === 'number' || dataType === 'boolean' || dataType === 'string') {
return dataType;
}
if (content instanceof Date) {
return 'date';
}
if (dataType === 'object' && content instanceof RegExp === false) {

@@ -176,3 +179,6 @@ return 'object';

*/
if (dataType === 'number' || dataType === 'boolean') {
if (dataType === 'object') {
content = utils_1.safeStringify(content);
}
else if (dataType === 'number' || dataType === 'boolean') {
content = String(content);

@@ -183,5 +189,2 @@ }

}
else if (dataType === 'object') {
content = JSON.stringify(content);
}
/*

@@ -188,0 +191,0 @@ * ----------------------------------------

@@ -59,2 +59,3 @@ "use strict";

ctx.routeKey = route.routeKey;
ctx.request.updateParams(ctx.params);
}

@@ -61,0 +62,0 @@ /**

@@ -11,2 +11,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.MiddlewareStore = exports.HttpContext = exports.Response = exports.Request = exports.Server = exports.Router = void 0;
var Router_1 = require("./src/Router");

@@ -13,0 +14,0 @@ Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return Router_1.Router; } });

{
"name": "@adonisjs/http-server",
"version": "3.0.3",
"version": "4.0.0",
"description": "AdonisJS HTTP server with support packed with Routing and Cookies",

@@ -38,18 +38,19 @@ "main": "build/providers/HttpServerProvider.js",

"devDependencies": {
"@adonisjs/application": "^2.0.0",
"@adonisjs/config": "^1.1.0",
"@adonisjs/application": "^3.0.0",
"@adonisjs/config": "^2.0.0",
"@adonisjs/encryption": "^2.0.6",
"@adonisjs/fold": "^6.3.5",
"@adonisjs/logger": "^2.1.0",
"@adonisjs/logger": "^3.0.0",
"@adonisjs/mrm-preset": "^2.4.0",
"@adonisjs/profiler": "^4.0.1",
"@poppinss/dev-utils": "^1.0.8",
"@adonisjs/profiler": "^5.0.1",
"@adonisjs/require-ts": "^1.0.0",
"@poppinss/dev-utils": "^1.0.10",
"@types/cookie": "^0.4.0",
"@types/ms": "^0.7.31",
"@types/node": "^14.6.1",
"@types/node": "^14.11.2",
"@types/pluralize": "0.0.29",
"@types/proxy-addr": "^2.0.0",
"@types/qs": "^6.9.4",
"@types/qs": "^6.9.5",
"@types/supertest": "^2.0.10",
"autocannon": "^6.1.0",
"autocannon": "^6.4.0",
"commitizen": "^4.2.1",

@@ -59,25 +60,25 @@ "cz-conventional-changelog": "^3.3.0",

"doctoc": "^1.4.0",
"eslint": "^7.7.0",
"eslint": "^7.9.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-adonis": "^1.0.14",
"eslint-plugin-adonis": "^1.0.15",
"eslint-plugin-prettier": "^3.1.4",
"fastify": "^3.3.0",
"fastify": "^3.4.1",
"github-label-sync": "^2.0.0",
"http-status-codes": "^2.1.2",
"husky": "^4.2.5",
"http-status-codes": "^2.1.4",
"husky": "^4.3.0",
"japa": "^3.1.1",
"mrm": "^2.3.5",
"np": "^6.4.0",
"mrm": "^2.5.1",
"np": "^6.5.0",
"npm-audit-html": "^1.4.3",
"pem": "^1.14.4",
"prettier": "^2.1.1",
"prettier": "^2.1.2",
"reflect-metadata": "^0.1.13",
"supertest": "^4.0.2",
"ts-node": "^9.0.0",
"typescript": "^3.9.7"
"typescript": "^4.0.3"
},
"peerDependencies": {
"@adonisjs/encryption": "^2.0.0",
"@adonisjs/logger": "^2.0.0",
"@adonisjs/profiler": "^4.0.0"
"@adonisjs/logger": "^3.0.0",
"@adonisjs/profiler": "^5.0.0"
},

@@ -108,5 +109,5 @@ "nyc": {

"dependencies": {
"@poppinss/utils": "^2.5.5",
"@poppinss/utils": "^2.5.7",
"accepts": "^1.3.7",
"co-compose": "^6.0.1",
"co-compose": "^6.0.3",
"content-disposition": "^0.5.3",

@@ -120,3 +121,3 @@ "cookie": "^0.4.1",

"haye": "^2.0.2",
"macroable": "^5.0.1",
"macroable": "^5.0.3",
"matchit": "git+https://github.com/thetutlage/matchit.git",

@@ -147,3 +148,7 @@ "mime-types": "^2.1.27",

"exceptions": "./build/exceptions.json"
},
"publishConfig": {
"access": "public",
"tag": "next"
}
}
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