* @see https://whatpr.org/websockets/48/7b748d3...d5570f3.html#get-a-url-record * @param {string} url * @param {string} [baseURL]
(url, baseURL)
| 252 | * @param {string} [baseURL] |
| 253 | */ |
| 254 | function getURLRecord (url, baseURL) { |
| 255 | // 1. Let urlRecord be the result of applying the URL parser to url with baseURL . |
| 256 | // 2. If urlRecord is failure, then throw a " SyntaxError " DOMException . |
| 257 | let urlRecord |
| 258 | |
| 259 | try { |
| 260 | urlRecord = new URL(url, baseURL) |
| 261 | } catch (e) { |
| 262 | throw new DOMException(e, 'SyntaxError') |
| 263 | } |
| 264 | |
| 265 | // 3. If urlRecord ’s scheme is " http ", then set urlRecord ’s scheme to " ws ". |
| 266 | // 4. Otherwise, if urlRecord ’s scheme is " https ", set urlRecord ’s scheme to " wss ". |
| 267 | if (urlRecord.protocol === 'http:') { |
| 268 | urlRecord.protocol = 'ws:' |
| 269 | } else if (urlRecord.protocol === 'https:') { |
| 270 | urlRecord.protocol = 'wss:' |
| 271 | } |
| 272 | |
| 273 | // 5. If urlRecord ’s scheme is not " ws " or " wss ", then throw a " SyntaxError " DOMException . |
| 274 | if (urlRecord.protocol !== 'ws:' && urlRecord.protocol !== 'wss:') { |
| 275 | throw new DOMException('expected a ws: or wss: url', 'SyntaxError') |
| 276 | } |
| 277 | |
| 278 | // If urlRecord ’s fragment is non-null, then throw a " SyntaxError " DOMException . |
| 279 | if (urlRecord.hash.length || urlRecord.href.endsWith('#')) { |
| 280 | throw new DOMException('hash', 'SyntaxError') |
| 281 | } |
| 282 | |
| 283 | // Return urlRecord . |
| 284 | return urlRecord |
| 285 | } |
| 286 | |
| 287 | // https://whatpr.org/websockets/48.html#validate-close-code-and-reason |
| 288 | function validateCloseCodeAndReason (code, reason) { |
no outgoing calls
no test coverage detected