source: trip-planner-front/node_modules/uri-js/dist/esnext/schemes/ws.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.6 KB
Line 
1function isSecure(wsComponents) {
2 return typeof wsComponents.secure === 'boolean' ? wsComponents.secure : String(wsComponents.scheme).toLowerCase() === "wss";
3}
4//RFC 6455
5const handler = {
6 scheme: "ws",
7 domainHost: true,
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;
16 return wsComponents;
17 },
18 serialize: function (wsComponents, options) {
19 //normalize the default port
20 if (wsComponents.port === (isSecure(wsComponents) ? 443 : 80) || wsComponents.port === "") {
21 wsComponents.port = undefined;
22 }
23 //ensure scheme matches secure flag
24 if (typeof wsComponents.secure === 'boolean') {
25 wsComponents.scheme = (wsComponents.secure ? 'wss' : 'ws');
26 wsComponents.secure = undefined;
27 }
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;
34 }
35 //forbid fragment component
36 wsComponents.fragment = undefined;
37 return wsComponents;
38 }
39};
40export default handler;
41//# sourceMappingURL=ws.js.map
Note: See TracBrowser for help on using the repository browser.