@fanoutio/grip
Advanced tools
Comparing version 3.0.4-beta.3 to 3.0.4-beta.4
@@ -38,3 +38,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import debug from './debug'; | ||
import { flattenHeader, readRequestBody } from "./http"; | ||
import { readRequestBody } from "./http"; | ||
import WebSocketContext from "../data/websocket/WebSocketContext"; | ||
@@ -59,2 +59,6 @@ import { decodeWebSocketEvents } from "./webSocketEvents"; | ||
var contentTypeHeader = req.headers['content-type']; | ||
if (contentTypeHeader != null) { | ||
contentTypeHeader = contentTypeHeader.split(';')[0]; | ||
contentTypeHeader = contentTypeHeader.trim(); | ||
} | ||
if (contentTypeHeader == null || contentTypeHeader === '') { | ||
@@ -64,4 +68,2 @@ debug("content-type header not present"); | ||
} | ||
contentTypeHeader = contentTypeHeader.split(';')[0]; | ||
contentTypeHeader = contentTypeHeader.trim(); | ||
debug("content-type header", contentTypeHeader); | ||
@@ -98,13 +100,25 @@ var acceptTypesHeader = req.headers['accept']; | ||
export function getWebSocketContext(req, body, prefix) { | ||
var _a; | ||
if (prefix === void 0) { prefix = ''; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var cid, subprotocols, meta, _i, _b, _c, key, value, lKey, k, events, wsContext; | ||
return __generator(this, function (_d) { | ||
cid = flattenHeader(req.headers['connection-id']); | ||
if (cid == null) { | ||
var cid, subprotocols, meta, _i, _a, _b, key, value, lKey, k, events, wsContext; | ||
return __generator(this, function (_c) { | ||
cid = req.headers['connection-id']; | ||
if (Array.isArray(cid)) { | ||
cid = cid.join(','); | ||
} | ||
if (cid != null) { | ||
cid = cid.split(',') | ||
.map(function (item) { return item.trim(); })[0]; | ||
} | ||
if (cid == null || cid === '') { | ||
throw new ConnectionIdMissingException(); | ||
} | ||
debug("Connection ID", cid); | ||
subprotocols = ((_a = req.headers['sec-websocket-protocol']) !== null && _a !== void 0 ? _a : '').split(','); | ||
subprotocols = req.headers['sec-websocket-protocol']; | ||
if (Array.isArray(subprotocols)) { | ||
subprotocols = subprotocols.join(','); | ||
} | ||
if (subprotocols != null) { | ||
subprotocols = subprotocols.split(',') | ||
.map(function (item) { return item.trim(); }); | ||
} | ||
debug("Request subprotocols", subprotocols); | ||
@@ -114,4 +128,4 @@ // Handle meta keys | ||
meta = {}; | ||
for (_i = 0, _b = Object.entries(req.headers); _i < _b.length; _i++) { | ||
_c = _b[_i], key = _c[0], value = _c[1]; | ||
for (_i = 0, _a = Object.entries(req.headers); _i < _a.length; _i++) { | ||
_b = _a[_i], key = _b[0], value = _b[1]; | ||
lKey = key.toLowerCase(); | ||
@@ -118,0 +132,0 @@ if (lKey.startsWith('meta-')) { |
@@ -5,3 +5,3 @@ /// <reference types="node" /> | ||
export interface IRequest { | ||
headers: IncomingHttpHeaders; | ||
headers: IncomingHttpHeaders | NodeJS.Dict<string>; | ||
method?: string; | ||
@@ -8,0 +8,0 @@ } |
@@ -64,2 +64,6 @@ "use strict"; | ||
var contentTypeHeader = req.headers['content-type']; | ||
if (contentTypeHeader != null) { | ||
contentTypeHeader = contentTypeHeader.split(';')[0]; | ||
contentTypeHeader = contentTypeHeader.trim(); | ||
} | ||
if (contentTypeHeader == null || contentTypeHeader === '') { | ||
@@ -69,4 +73,2 @@ debug_1.default("content-type header not present"); | ||
} | ||
contentTypeHeader = contentTypeHeader.split(';')[0]; | ||
contentTypeHeader = contentTypeHeader.trim(); | ||
debug_1.default("content-type header", contentTypeHeader); | ||
@@ -105,13 +107,25 @@ var acceptTypesHeader = req.headers['accept']; | ||
function getWebSocketContext(req, body, prefix) { | ||
var _a; | ||
if (prefix === void 0) { prefix = ''; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var cid, subprotocols, meta, _i, _b, _c, key, value, lKey, k, events, wsContext; | ||
return __generator(this, function (_d) { | ||
cid = http_1.flattenHeader(req.headers['connection-id']); | ||
if (cid == null) { | ||
var cid, subprotocols, meta, _i, _a, _b, key, value, lKey, k, events, wsContext; | ||
return __generator(this, function (_c) { | ||
cid = req.headers['connection-id']; | ||
if (Array.isArray(cid)) { | ||
cid = cid.join(','); | ||
} | ||
if (cid != null) { | ||
cid = cid.split(',') | ||
.map(function (item) { return item.trim(); })[0]; | ||
} | ||
if (cid == null || cid === '') { | ||
throw new ConnectionIdMissingException_1.default(); | ||
} | ||
debug_1.default("Connection ID", cid); | ||
subprotocols = ((_a = req.headers['sec-websocket-protocol']) !== null && _a !== void 0 ? _a : '').split(','); | ||
subprotocols = req.headers['sec-websocket-protocol']; | ||
if (Array.isArray(subprotocols)) { | ||
subprotocols = subprotocols.join(','); | ||
} | ||
if (subprotocols != null) { | ||
subprotocols = subprotocols.split(',') | ||
.map(function (item) { return item.trim(); }); | ||
} | ||
debug_1.default("Request subprotocols", subprotocols); | ||
@@ -121,4 +135,4 @@ // Handle meta keys | ||
meta = {}; | ||
for (_i = 0, _b = Object.entries(req.headers); _i < _b.length; _i++) { | ||
_c = _b[_i], key = _c[0], value = _c[1]; | ||
for (_i = 0, _a = Object.entries(req.headers); _i < _a.length; _i++) { | ||
_b = _a[_i], key = _b[0], value = _b[1]; | ||
lKey = key.toLowerCase(); | ||
@@ -125,0 +139,0 @@ if (lKey.startsWith('meta-')) { |
{ | ||
"name": "@fanoutio/grip", | ||
"version": "3.0.4-beta.3", | ||
"version": "3.0.4-beta.4", | ||
"author": "Fanout, Inc. <info@fanout.io>", | ||
@@ -5,0 +5,0 @@ "description": "GRIP Interface Library", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
5724186
37841