summary refs log tree commit diff stats
path: root/doc/pydoc/ranger.defaults.options.html
diff options
context:
space:
mode:
Diffstat (limited to 'doc/pydoc/ranger.defaults.options.html')
0 files changed, 0 insertions, 0 deletions
ort external stylesheets' href='/ahoang/chawan/commit/src/io/loader.nim?id=010185f7c306f2465b691a82fcbfe1c76513f8fc'>010185f7 ^
8fb2b9a0 ^



010185f7 ^


4f5e4539 ^



010185f7 ^




fb017f27 ^
010185f7 ^
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48















                          







                                        



                                   
                                                                                                                                                          
                          



                                                          


                                                     



                                                                                                 




                                                                 
                                  
                              
import httpclient
import options
import streams

import types/mime
import types/url
import utils/twtstr

type
  FileLoader* = ref object
    http: HttpClient

  LoadResult* = object
    s*: Stream
    contenttype*: string

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",
}

proc newFileLoader*(): FileLoader =
  new(result)
  result.http = newHttpClient()

proc getPage*(loader: FileLoader, url: Url, smethod: HttpMethod = HttpGet, mimetype = "", body: string = "", multipart: MultipartData = nil): LoadResult =
  if url.scheme == "file":
    when defined(windows) or defined(OS2) or defined(DOS):
      let path = url.path.serialize_unicode_windows()
    else:
      let path = url.path.serialize_unicode()
    result.contenttype = guessContentType(path)
    result.s = newFileStream(path, fmRead)
  elif url.scheme == "http" or url.scheme == "https":
    var requestheaders = newHttpHeaders(DefaultHeaders, true)
    if mimetype != "":
      requestheaders["Content-Type"] = mimetype 
    let resp = loader.http.request(url.serialize(true), smethod, body, requestheaders, multipart)
    let ct = resp.contentType()
    if ct != "":
      result.contenttype = ct.until(';')
    else:
      result.contenttype = guessContentType(url.path.serialize())
    resp.bodystream.setPosition(0)
    result.s = resp.bodyStream