• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2
3const assert = require('assert')
4const { URLSerializer } = require('../fetch/dataURL')
5const { isValidHeaderName } = require('../fetch/util')
6
7/**
8 * @see https://url.spec.whatwg.org/#concept-url-equals
9 * @param {URL} A
10 * @param {URL} B
11 * @param {boolean | undefined} excludeFragment
12 * @returns {boolean}
13 */
14function urlEquals (A, B, excludeFragment = false) {
15  const serializedA = URLSerializer(A, excludeFragment)
16
17  const serializedB = URLSerializer(B, excludeFragment)
18
19  return serializedA === serializedB
20}
21
22/**
23 * @see https://github.com/chromium/chromium/blob/694d20d134cb553d8d89e5500b9148012b1ba299/content/browser/cache_storage/cache_storage_cache.cc#L260-L262
24 * @param {string} header
25 */
26function fieldValues (header) {
27  assert(header !== null)
28
29  const values = []
30
31  for (let value of header.split(',')) {
32    value = value.trim()
33
34    if (!value.length) {
35      continue
36    } else if (!isValidHeaderName(value)) {
37      continue
38    }
39
40    values.push(value)
41  }
42
43  return values
44}
45
46module.exports = {
47  urlEquals,
48  fieldValues
49}
50