1 function isSecure(wsComponents) {
2 return typeof wsComponents.secure === 'boolean' ? wsComponents.secure : String(wsComponents.scheme).toLowerCase() === "wss";
8 parse: function (components, options) {
9 const wsComponents = components;
10 //indicate if the secure flag is set
11 wsComponents.secure = isSecure(wsComponents);
12 //construct resouce name
13 wsComponents.resourceName = (wsComponents.path || '/') + (wsComponents.query ? '?' + wsComponents.query : '');
14 wsComponents.path = undefined;
15 wsComponents.query = undefined;
18 serialize: function (wsComponents, options) {
19 //normalize the default port
20 if (wsComponents.port === (isSecure(wsComponents) ? 443 : 80) || wsComponents.port === "") {
21 wsComponents.port = undefined;
23 //ensure scheme matches secure flag
24 if (typeof wsComponents.secure === 'boolean') {
25 wsComponents.scheme = (wsComponents.secure ? 'wss' : 'ws');
26 wsComponents.secure = undefined;
28 //reconstruct path from resource name
29 if (wsComponents.resourceName) {
30 const [path, query] = wsComponents.resourceName.split('?');
31 wsComponents.path = (path && path !== '/' ? path : undefined);
32 wsComponents.query = query;
33 wsComponents.resourceName = undefined;
35 //forbid fragment component
36 wsComponents.fragment = undefined;
40 export default handler;
41 //# sourceMappingURL=ws.js.map