diff --git a/lerna.json b/lerna.json index 51eadf64..6d1744c8 100644 --- a/lerna.json +++ b/lerna.json @@ -1,4 +1,4 @@ { - "$schema": "node_modules/lerna/schemas/lerna-schema.json", - "version": "0.32.15" -} \ No newline at end of file + "$schema": "node_modules/lerna/schemas/lerna-schema.json", + "version": "0.32.15" +} diff --git a/packages/tslua-base64/package.json b/packages/tslua-base64/package.json index 42f8d930..2d907629 100644 --- a/packages/tslua-base64/package.json +++ b/packages/tslua-base64/package.json @@ -2,11 +2,7 @@ "name": "@flying-dice/tslua-base64", "version": "0.32.15", "description": "Base64 library with typings", - "keywords": [ - "lua", - "dcs", - "base64" - ], + "keywords": ["lua", "dcs", "base64"], "repository": { "type": "git", "url": "https://github.com/flying-dice/tslua-dcs.git" diff --git a/packages/tslua-common/package.json b/packages/tslua-common/package.json index e3c517d4..858cd633 100644 --- a/packages/tslua-common/package.json +++ b/packages/tslua-common/package.json @@ -2,11 +2,7 @@ "name": "@flying-dice/tslua-common", "version": "0.32.15", "description": "Common Utils Library", - "keywords": [ - "lua", - "dcs", - "logger" - ], + "keywords": ["lua", "dcs", "logger"], "repository": { "type": "git", "url": "https://github.com/flying-dice/tslua-dcs.git" diff --git a/packages/tslua-dcs-gui-types/package.json b/packages/tslua-dcs-gui-types/package.json index b79ef13d..c80b5d3b 100644 --- a/packages/tslua-dcs-gui-types/package.json +++ b/packages/tslua-dcs-gui-types/package.json @@ -2,11 +2,7 @@ "name": "@flying-dice/tslua-dcs-gui-types", "version": "0.32.15", "description": "Typescript type definitions for DCS GUI environment", - "keywords": [ - "lua", - "dcs", - "gui" - ], + "keywords": ["lua", "dcs", "gui"], "repository": { "type": "git", "url": "https://github.com/flying-dice/tslua-dcs.git" diff --git a/packages/tslua-dcs-mission-types/package.json b/packages/tslua-dcs-mission-types/package.json index 6bd68e25..bd18d2f1 100644 --- a/packages/tslua-dcs-mission-types/package.json +++ b/packages/tslua-dcs-mission-types/package.json @@ -2,11 +2,7 @@ "name": "@flying-dice/tslua-dcs-mission-types", "version": "0.32.15", "description": "Typescript type definitions for DCS", - "keywords": [ - "lua", - "dcs", - "mission" - ], + "keywords": ["lua", "dcs", "mission"], "repository": { "type": "git", "url": "https://github.com/flying-dice/tslua-dcs.git" diff --git a/packages/tslua-http-api/package.json b/packages/tslua-http-api/package.json index 208b410c..c89d507a 100644 --- a/packages/tslua-http-api/package.json +++ b/packages/tslua-http-api/package.json @@ -2,11 +2,7 @@ "name": "@flying-dice/tslua-http-api", "version": "0.32.15", "description": "LUA HTTP API Server written in Typescript Transpiled to lua using TypeScriptToLua", - "keywords": [ - "lua", - "http", - "api" - ], + "keywords": ["lua", "http", "api"], "repository": { "type": "git", "url": "https://github.com/flying-dice/tslua-dcs.git" diff --git a/packages/tslua-http-api/src/application.ts b/packages/tslua-http-api/src/application.ts index 06ef21e3..5ed91667 100644 --- a/packages/tslua-http-api/src/application.ts +++ b/packages/tslua-http-api/src/application.ts @@ -13,18 +13,21 @@ import { getPathParameters, isMatch } from "./path"; export class AppHttpRequest { protected logger = new Logger("AppHttpRequest"); + /** + * @deprecated Use getQueryParameterValue and getQueryParameterValueOrThrow + */ get query(): QUERY { return this.req.parameters as QUERY; } + /** + * @deprecated Use getBody and getBodyOrThrow + */ get body(): BODY | undefined { if (!this.req.body) return undefined; // Body Parse JSON - if ( - this.getHeaderValue("content-type") === "application/json" || - this.getHeaderValue("Content-Type") === "application/json" - ) { + if (this.getHeaderValue("content-type") === "application/json") { try { return json.decode(this.req.body) as BODY; } catch (e) { @@ -36,12 +39,18 @@ export class AppHttpRequest { return this.req.body as BODY; } + /** + * @deprecated Use getPathParameterValue and getPathParameterValueOrThrow + */ get params(): PARAMS { return this.__params as PARAMS; } __params: Record; + /** + * @deprecated Use getHeaderValue and getHeaderValueOrThrow + */ get headers() { return this.req.headers; } @@ -71,17 +80,17 @@ export class AppHttpRequest { } getHeaderValue(key: string) { - return this.req.headers[key] as T; + return this.req.headers[key.toLowerCase()] as T; } getHeaderValueOrThrow( key: string, error = new Error("Header is not defined"), ) { - if (this.req.headers[key] === undefined) { + if (this.req.headers[key.toLowerCase()] === undefined) { throw error; } - return this.req.headers[key] as T; + return this.req.headers[key.toLowerCase()] as T; } getBody() { diff --git a/packages/tslua-http-api/src/test-app.ts b/packages/tslua-http-api/src/test-app.ts index ef8c934e..f6b6c1b0 100644 --- a/packages/tslua-http-api/src/test-app.ts +++ b/packages/tslua-http-api/src/test-app.ts @@ -74,7 +74,7 @@ app.get("/complex/:id", (req, res) => { }); const authMiddleware: AppMiddleware = (req, res, next) => { - if (req.headers.Authorization !== "Bearer 123") { + if (req.getHeaderValue("Authorization") !== "Bearer 123") { return res.status(HttpStatus.UNAUTHORIZED).send("Unauthorized"); } diff --git a/packages/tslua-http/package.json b/packages/tslua-http/package.json index f9e6a359..e8ecc079 100644 --- a/packages/tslua-http/package.json +++ b/packages/tslua-http/package.json @@ -2,10 +2,7 @@ "name": "@flying-dice/tslua-http", "version": "0.32.15", "description": "LUA HTTP Server written in Typescript Transpiled to lua using TypeScriptToLua", - "keywords": [ - "lua", - "http" - ], + "keywords": ["lua", "http"], "repository": { "type": "git", "url": "https://github.com/flying-dice/tslua-dcs.git" diff --git a/packages/tslua-http/src/request.test.ts b/packages/tslua-http/src/request.test.ts index 1671f054..66d155ce 100644 --- a/packages/tslua-http/src/request.test.ts +++ b/packages/tslua-http/src/request.test.ts @@ -8,7 +8,7 @@ describe("readRequestHead", () => { method: "GET", originalUrl: "/home", protocol: "HTTP/1.1", - headers: { Host: "example.com" }, + headers: { host: "example.com" }, path: "/home", parameters: {}, }; @@ -23,7 +23,7 @@ describe("readRequestHead", () => { method: "POST", originalUrl: "/submit", protocol: "HTTP/1.1", - headers: { Host: "example.com", "Content-Type": "application/json" }, + headers: { host: "example.com", "content-type": "application/json" }, path: "/submit", parameters: {}, }; @@ -38,7 +38,7 @@ describe("readRequestHead", () => { method: "GET", originalUrl: "/search?q=test", protocol: "HTTP/1.1", - headers: { Host: "example.com" }, + headers: { host: "example.com" }, path: "/search", parameters: { q: "test" }, }; diff --git a/packages/tslua-http/src/request.ts b/packages/tslua-http/src/request.ts index a7b953ea..8bacaaa4 100644 --- a/packages/tslua-http/src/request.ts +++ b/packages/tslua-http/src/request.ts @@ -74,7 +74,7 @@ export const readRequestHead = (requestPayload: string): HttpRequest => { for (const headerLine of headerLines) { if (headerLine === "") break; const [key, value] = headerLine.split(":"); - httpRequest.headers[key.trim()] = value.trim(); + httpRequest.headers[key.trim().toLowerCase()] = value.trim(); } return httpRequest; diff --git a/packages/tslua-http/src/server.ts b/packages/tslua-http/src/server.ts index f1fb8e93..aa6b07e9 100644 --- a/packages/tslua-http/src/server.ts +++ b/packages/tslua-http/src/server.ts @@ -109,12 +109,10 @@ export class HttpServer { this.logger.debug("Received request head"); const request = readRequestHead(requestHeadLines.join(CRLF)); - const contentLength = request.headers["Content-Length"]; + const contentLength = request.headers["content-length"]; const contentLengthNum = tonumber(contentLength); if (contentLengthNum && contentLengthNum > 0) { - this.logger.debug( - `Fetching request body ${request.headers["Content-Length"]}`, - ); + this.logger.debug(`Fetching request body ${contentLength}`); client.settimeout(2); request.body = client.receive(contentLengthNum) as string; diff --git a/packages/tslua-luatest/package.json b/packages/tslua-luatest/package.json index c1b812a9..4ef0bcf6 100644 --- a/packages/tslua-luatest/package.json +++ b/packages/tslua-luatest/package.json @@ -2,11 +2,7 @@ "name": "@flying-dice/tslua-luatest", "version": "0.32.15", "description": "tslua testing library", - "keywords": [ - "lua", - "dcs", - "test" - ], + "keywords": ["lua", "dcs", "test"], "repository": { "type": "git", "url": "https://github.com/flying-dice/tslua-dcs.git" diff --git a/packages/tslua-openapi/package.json b/packages/tslua-openapi/package.json index 75d3851f..a1e3727b 100644 --- a/packages/tslua-openapi/package.json +++ b/packages/tslua-openapi/package.json @@ -2,12 +2,7 @@ "name": "@flying-dice/tslua-openapi", "version": "0.32.15", "description": "Re-export of https://github.com/metadevpro/openapi3-ts/ library for tslua", - "keywords": [ - "lua", - "http", - "api", - "openapi" - ], + "keywords": ["lua", "http", "api", "openapi"], "repository": { "type": "git", "url": "https://github.com/flying-dice/tslua-dcs.git" diff --git a/packages/tslua-rxi-json/package.json b/packages/tslua-rxi-json/package.json index 157b3d51..e8b5ca5f 100644 --- a/packages/tslua-rxi-json/package.json +++ b/packages/tslua-rxi-json/package.json @@ -4,12 +4,7 @@ "description": "rxi-json library with typings", "types": "./index.d.ts", "main": "./index", - "keywords": [ - "lua", - "dcs", - "json", - "rxi/json" - ], + "keywords": ["lua", "dcs", "json", "rxi/json"], "repository": { "type": "git", "url": "https://github.com/flying-dice/tslua-dcs.git"