about summary refs log tree commit diff stats
path: root/src/loader/curlhandle.nim
blob: 3c69c6c0bb955768b89aa33415796fa64d823965 (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
26
27
28
29
30
31
32
import bindings/curl
import loader/headers
import loader/loaderhandle
import loader/request

type
  CurlHandle* = ref object of RootObj
    curl*: CURL
    statusline*: bool
    headers*: Headers
    request*: Request
    handle*: LoaderHandle
    mime*: curl_mime
    slist*: curl_slist
    finish*: proc(handle: CurlHandle)

func newCurlHandle*(curl: CURL, request: Request, handle: LoaderHandle):
    CurlHandle =
  return CurlHandle(
    headers: newHeaders(),
    curl: curl,
    handle: handle,
    request: request
  )

proc cleanup*(handleData: CurlHandle) =
  handleData.handle.close()
  if handleData.mime != nil:
    curl_mime_free(handleData.mime)
  if handleData.slist != nil:
    curl_slist_free_all(handleData.slist)
  curl_easy_cleanup(handleData.curl)