about summary refs log tree commit diff stats
path: root/src/config/config.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-08-26 10:58:10 +0200
committerbptato <nincsnevem662@gmail.com>2023-08-26 10:58:10 +0200
commite5d170aa66a9fdc2ba2258f42d054d7d998e5915 (patch)
treefe398035de20112de76701b95c695303638ca6f1 /src/config/config.nim
parenta11e9468001f19ac3874bec540a5a9cbd94739bc (diff)
downloadchawan-e5d170aa66a9fdc2ba2258f42d054d7d998e5915.tar.gz
Allow overriding default headers
Diffstat (limited to 'src/config/config.nim')
-rw-r--r--src/config/config.nim14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/config/config.nim b/src/config/config.nim
index e5dbad9c..afffdf23 100644
--- a/src/config/config.nim
+++ b/src/config/config.nim
@@ -90,6 +90,7 @@ type
     max_redirect*: int32
     prepend_https*: bool
     proxy*: Opt[string]
+    default_headers*: Table[string, string]
 
   DisplayConfig = object
     color_mode*: Opt[ColorMode]
@@ -141,14 +142,6 @@ type
 
 jsDestructor(Config)
 
-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().newHeaders()[]
-
 func getForkServerConfig*(config: Config): ForkServerConfig =
   return ForkServerConfig(
     tmpdir: config.external.tmpdir,
@@ -165,6 +158,9 @@ func getProxy*(config: Config): URL =
       raise newException(Defect, "Invalid proxy URL: " & s)
   return nil
 
+func getDefaultHeaders*(config: Config): Headers =
+  return newHeaders(config.network.default_headers)
+
 proc getBufferConfig*(config: Config, location: URL, cookiejar: CookieJar,
     headers: Headers, referer_from, scripting: bool, charsets: seq[Charset],
     images: bool, userstyle: string, proxy: URL, mimeTypes: MimeTypes):
@@ -181,8 +177,6 @@ proc getBufferConfig*(config: Config, location: URL, cookiejar: CookieJar,
     proxy: proxy,
     mimeTypes: mimeTypes
   )
-  new(result.headers)
-  result.headers[] = DefaultHeaders
 
 proc getSiteConfig*(config: Config, jsctx: JSContext): seq[SiteConfig] =
   for sc in config.siteconf: