about summary refs log tree commit diff stats
path: root/src/types/buffersource.nim
blob: 9b4e1814ac67a1e9a81e4de55ffef8bc51ebb8b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import options

when defined(posix):
  import posix

import loader/request
import types/url

import chakasu/charset

type
  BufferSourceType* = enum
    CLONE, LOAD_REQUEST, LOAD_PIPE

  BufferSource* = object
    location*: URL
    contentType*: Option[string] # override
    charset*: Charset # fallback
    case t*: BufferSourceType
    of CLONE:
      clonepid*: Pid
    of LOAD_REQUEST:
      request*: Request
    of LOAD_PIPE:
      fd*: FileHandle
l">"no-referrer-when-downgrade": return some(NO_REFERRER_WHEN_DOWNGRADE) of "origin": return some(ORIGIN) of "origin-when-cross-origin": return some(ORIGIN_WHEN_CROSS_ORIGIN) of "same-origin": return some(SAME_ORIGIN) of "strict-origin": return some(STRICT_ORIGIN) of "strict-origin-when-cross-origin": return some(STRICT_ORIGIN_WHEN_CROSS_ORIGIN) of "unsafe-url": return some(UNSAFE_URL) proc getReferer*(prev, target: URL, policy: ReferrerPolicy): string = let origin = prev.origin0 if origin.isNone: return "" if prev.scheme != "http" and prev.scheme != "https": return "" if target.scheme != "http" and target.scheme != "https": return "" case policy of NO_REFERRER: return "" of NO_REFERRER_WHEN_DOWNGRADE: if prev.scheme == "https" and target.scheme == "http": return "" return $origin & prev.pathname & prev.search of SAME_ORIGIN: if origin == target.origin0: return $origin return "" of ORIGIN: return $origin of STRICT_ORIGIN: if prev.scheme == "https" and target.scheme == "http": return "" return $origin of ORIGIN_WHEN_CROSS_ORIGIN: if origin != target.origin0: return $origin return $origin & prev.pathname & prev.search of STRICT_ORIGIN_WHEN_CROSS_ORIGIN: if prev.scheme == "https" and target.scheme == "http": return $origin if origin != target.origin0: return $origin return $origin & prev.pathname & prev.search of UNSAFE_URL: return $origin & prev.pathname & prev.search