diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-13 22:55:43 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-13 22:55:43 +0100 |
commit | e80ae4b136fe82f916868e1e9b728d69c403a70a (patch) | |
tree | d112f10934818394c746b9179de53552b9c778a1 /src/config | |
parent | 4b482418c22ea31729ca94583ffd2a6aa167d811 (diff) | |
download | chawan-e80ae4b136fe82f916868e1e9b728d69c403a70a.tar.gz |
Add referer support, re-render on windowChange
Diffstat (limited to 'src/config')
-rw-r--r-- | src/config/config.nim | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/config/config.nim b/src/config/config.nim index 850ccb71..220b3948 100644 --- a/src/config/config.nim +++ b/src/config/config.nim @@ -11,6 +11,7 @@ import js/javascript import js/regex import types/color import types/cookie +import types/referer import types/url import utils/twtstr @@ -26,9 +27,10 @@ type url: Option[string] host: Option[string] subst: Option[string] - cookie: bool + cookie: Option[bool] thirdpartycookie: seq[string] sharecookiejar: Option[string] + refererfrom*: Option[bool] StaticOmniRule = object match: string @@ -38,9 +40,10 @@ type url*: Option[Regex] host*: Option[Regex] subst*: (proc(s: URL): Option[URL]) - cookie*: bool + cookie*: Option[bool] thirdpartycookie*: seq[Regex] sharecookiejar*: Option[string] + refererfrom*: Option[bool] OmniRule* = object match*: Regex @@ -76,27 +79,45 @@ type filter*: URLFilter cookiejar*: CookieJar headers*: HeaderList + refererfrom*: bool + referrerpolicy*: ReferrerPolicy ForkServerConfig* = object tmpdir*: string ambiguous_double*: bool +const DefaultHeaders* = { + "User-Agent": "chawan", + "Accept": "text/html,text/*;q=0.5", + "Accept-Language": "en;q=1.0", + "Pragma": "no-cache", + "Cache-Control": "no-cache", +}.toTable().newHeaderList()[] + func getForkServerConfig*(config: Config): ForkServerConfig = return ForkServerConfig( tmpdir: config.tmpdir, ambiguous_double: config.ambiguous_double ) -func getBufferConfig*(config: Config, location: URL, cookiejar: CookieJar): BufferConfig = - result.userstyle = config.stylesheet - result.filter = newURLFilter(scheme = some(location.scheme), default = true) - result.cookiejar = cookiejar +proc getBufferConfig*(config: Config, location: URL, cookiejar: CookieJar = nil, + headers: HeaderList = nil, refererfrom = false): BufferConfig = + result = BufferConfig( + userstyle: config.stylesheet, + filter: newURLFilter(scheme = some(location.scheme), default = true), + cookiejar: cookiejar, + headers: headers, + refererfrom: refererfrom + ) + new(result.headers) + result.headers[] = DefaultHeaders proc getSiteConfig*(config: Config, jsctx: JSContext): seq[SiteConfig] = for sc in config.siteconf: var conf = SiteConfig( cookie: sc.cookie, - sharecookiejar: sc.sharecookiejar + sharecookiejar: sc.sharecookiejar, + refererfrom: sc.refererfrom ) if sc.url.isSome: conf.url = compileRegex(sc.url.get, 0) @@ -327,7 +348,8 @@ proc parseConfig(config: Config, dir: string, t: TomlValue) = of "url": conf.url = some(v.s) of "host": conf.host = some(v.s) of "rewrite-url": conf.subst = some(v.s) - of "cookie": conf.cookie = v.b + of "referer-from": conf.refererfrom = some(v.b) + of "cookie": conf.cookie = some(v.b) of "third-party-cookie": if v.vt == VALUE_STRING: conf.thirdpartycookie = @[v.s] |