diff options
author | bptato <nincsnevem662@gmail.com> | 2024-02-22 22:54:53 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-02-22 23:09:54 +0100 |
commit | 8ad93c79084e74b29b9d32ce8d9675439e02e0b0 (patch) | |
tree | 21f7958e3e97efcdd93dbd0e71a9c23bc1cf3a6f /src/local | |
parent | 6f68626e202f93991f678086634692e6366958c6 (diff) | |
download | chawan-8ad93c79084e74b29b9d32ce8d9675439e02e0b0.tar.gz |
buffer: remove BufferSource
Aside from being a wrapper of Request, it was just storing the -I charset, except even that didn't actually work. Whoops. This fixes -I effectively not doing anything; now it's a forced override that even disables BOM sniffing. (If the user wants to decode a file using a certain encoding, it seems wise to assume that they really meant it.)
Diffstat (limited to 'src/local')
-rw-r--r-- | src/local/container.nim | 38 | ||||
-rw-r--r-- | src/local/pager.nim | 30 |
2 files changed, 30 insertions, 38 deletions
diff --git a/src/local/container.nim b/src/local/container.nim index 4114566b..3bab3130 100644 --- a/src/local/container.nim +++ b/src/local/container.nim @@ -91,6 +91,8 @@ type # note: this is not the same as source.request.url (but should be synced # with buffer.url) url: URL + #TODO this is inaccurate, because only the network charset is passed through + charset*: Charset parent* {.jsget.}: Container children* {.jsget.}: seq[Container] config*: BufferConfig @@ -100,7 +102,7 @@ type title*: string # used in status msg hovertext: array[HoverType, string] lastpeek: HoverType - source*: BufferSource + request*: Request # source request # if set, this *overrides* any content type received from the network. (this # is because it stores the content type from the -T flag.) contentType* {.jsget.}: Option[string] @@ -140,22 +142,22 @@ jsDestructor(Highlight) jsDestructor(Container) proc newBuffer*(forkserver: ForkServer, config: BufferConfig, - source: BufferSource, attrs: WindowAttributes, title = "", + request: Request, attrs: WindowAttributes, title = "", redirectdepth = 0, canreinterpret = true, fd = FileHandle(-1), contentType: Option[string]): Container = - let (process, loaderPid) = forkserver.forkBuffer(source, config, attrs) + let (process, loaderPid) = forkserver.forkBuffer(request, config, attrs) if fd != -1: - loaderPid.passFd(source.request.url.host, fd) + loaderPid.passFd(request.url.host, fd) if fd == 0: # We are passing stdin. closeStdin() else: discard close(fd) return Container( - url: source.request.url, + url: request.url, process: process, loaderPid: loaderPid, - source: source, + request: request, contentType: contentType, width: attrs.width, height: attrs.height - 1, @@ -170,16 +172,14 @@ proc newBuffer*(forkserver: ForkServer, config: BufferConfig, proc newBufferFrom*(forkserver: ForkServer, attrs: WindowAttributes, container: Container, contentTypeOverride: string): Container = - container.contentType = some(contentTypeOverride) - var source = container.source - source.request = newRequest(source.request.url, fromcache = true) + let request = newRequest(container.request.url, fromcache = true) let config = container.config let loaderPid = container.loaderPid - let bufferPid = forkserver.forkBufferWithLoader(source, config, attrs, + let bufferPid = forkserver.forkBufferWithLoader(request, config, attrs, loaderPid) return Container( - url: source.request.url, - source: source, + url: request.url, + request: request, width: container.width, height: container.height, title: container.title, @@ -189,7 +189,8 @@ proc newBufferFrom*(forkserver: ForkServer, attrs: WindowAttributes, pos: CursorPosition( setx: -1 ), - canreinterpret: true + canreinterpret: true, + contentType: some(contentTypeOverride) ) func location*(container: Container): URL {.jsfget.} = @@ -212,7 +213,7 @@ proc clone*(container: Container, newurl: URL): Promise[Container] = title: container.title, hovertext: container.hovertext, lastpeek: container.lastpeek, - source: container.source, + request: container.request, pos: container.pos, bpos: container.bpos, highlights: container.highlights, @@ -238,9 +239,6 @@ proc clone*(container: Container, newurl: URL): Promise[Container] = ) ) -func charset*(container: Container): Charset = - return container.source.charset - func lineLoaded(container: Container, y: int): bool = return y - container.lineshift in 0..container.lines.high @@ -1389,15 +1387,15 @@ proc load(container: Container) = if res.cookies.len > 0 and cookiejar != nil: cookiejar.add(res.cookies) # set referrer policy, if any - if res.referrerpolicy.isSome and container.config.referer_from: - container.config.referrerpolicy = res.referrerpolicy.get + if res.referrerPolicy.isSome and container.config.referer_from: + container.config.referrerPolicy = res.referrerPolicy.get container.setLoadInfo("Connected to " & $container.location & ". Downloading...") if res.needsAuth: container.triggerEvent(NEEDS_AUTH) if res.redirect != nil: container.triggerEvent(ContainerEvent(t: REDIRECT, request: res.redirect)) - container.source.charset = res.charset + container.charset = res.charset if container.contentType.isNone: if res.contentType == "application/octet-stream": let contentType = guessContentType(container.location.pathname, diff --git a/src/local/pager.nim b/src/local/pager.nim index 37d6ada8..36924ead 100644 --- a/src/local/pager.nim +++ b/src/local/pager.nim @@ -451,13 +451,13 @@ proc addContainer*(pager: Pager, container: Container) = pager.registerContainer(container) pager.setContainer(container) -proc newBuffer(pager: Pager, bufferConfig: BufferConfig, source: BufferSource, +proc newBuffer(pager: Pager, bufferConfig: BufferConfig, request: Request, title = "", redirectdepth = 0, canreinterpret = true, fd = FileHandle(-1), contentType = none(string)): Container = return newBuffer( pager.forkserver, bufferConfig, - source, + request, pager.attrs, title, redirectdepth, @@ -688,7 +688,8 @@ proc gotoURL(pager: Pager, request: Request, prevurl = none(URL), redirectdepth = 0, referrer: Container = nil) = if referrer != nil and referrer.config.referer_from: request.referer = referrer.location - var bufferconfig = pager.applySiteconf(request.url) + var bufferConfig = pager.applySiteconf(request.url) + bufferConfig.charsetOverride = cs if prevurl.isNone or not prevurl.get.equals(request.url, true) or request.url.hash == "" or request.httpMethod != HTTP_GET: # Basically, we want to reload the page *only* when @@ -697,15 +698,11 @@ proc gotoURL(pager: Pager, request: Request, prevurl = none(URL), # I think this makes navigation pretty natural, or at least very close to # what other browsers do. Still, it would be nice if we got some visual # feedback on what is actually going to happen when typing a URL; TODO. - let source = BufferSource( - request: request, - charset: cs - ) if referrer != nil: - bufferconfig.referrerpolicy = referrer.config.referrerpolicy + bufferConfig.referrerPolicy = referrer.config.referrerPolicy let container = pager.newBuffer( - bufferconfig, - source, + bufferConfig, + request, redirectdepth = redirectdepth, contentType = contentType ) @@ -768,14 +765,11 @@ proc readPipe0*(pager: Pager, ctype: Option[string], cs: Charset, fd: FileHandle, location: Option[URL], title: string, canreinterpret: bool): Container = var location = location.get(newURL("stream:-").get) - let bufferconfig = pager.applySiteconf(location) - let source = BufferSource( - request: newRequest(location), - charset: cs - ) + var bufferConfig = pager.applySiteconf(location) + bufferConfig.charsetOverride = cs return pager.newBuffer( - bufferconfig, - source, + bufferConfig, + newRequest(location), title = title, canreinterpret = canreinterpret, fd = fd, @@ -1157,7 +1151,7 @@ proc checkMailcap(pager: Pager, container: Container): CheckMailcapResult = return (nil, true) #TODO callback for outpath or something let url = container.location - let cs = container.source.charset + let cs = container.charset let entry = pager.mailcap.getMailcapEntry(contentType, "", url, cs) if entry != nil: let tmpdir = pager.tmpdir |