src/curly

Search:
Group by:
Source   Edit  

Types

BatchedRequest = object
  verb*: string
  url*: string
  headers*: HttpHeaders
  body*: string
  tag*: string
Source   Edit  
CurlPool = ptr CurlPoolObj
Source   Edit  
Curly = ptr CurlyObj
Source   Edit  
CurlyObj = object
Source   Edit  
RequestBatch = object
Source   Edit  
RequestInfo = object
  verb*: string              ## HTTP method / verb of the request
  url*: string               ## Intitial request URL, before any redirects
  tag*: string               ## Arbtitrary user-provided data when batching requests
Source   Edit  
Response = object
  code*: int                 ## HTTP status code of the response
  url*: string               ## Final URL, after any redirects
  headers*: HttpHeaders
  body*: string              ## The response body (uncompressed if gzip'ed)
  request*: RequestInfo      ## Info about the request this response is for
Source   Edit  
ResponseBatch = seq[tuple[response: Response, error: string]]
Source   Edit  
ResponseStream = object
  code*: int                 ## HTTP status code of the response
  url*: string               ## Final URL, after any redirects
  headers*: HttpHeaders
  request*: RequestInfo      ## Info about the request this response is for
Source   Edit  

Procs

proc `[]`(batch: RequestBatch; i: int): lent BatchedRequest {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc addRequest(batch: var RequestBatch; verb: sink string; url: sink string;
                headers: sink HttpHeaders = emptyHttpHeaders();
                body: sink string = ""; tag: sink string = "") {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc borrow(pool: CurlPool): PCurl {.inline, ...raises: [], gcsafe, tags: [],
                                     forbids: [].}
Removes a libcurl handle from the pool. This call blocks until it can take a handle. Remember to add the handle back to the pool with recycle when you're finished with it. Source   Edit  
proc clearQueue(curl: Curly) {....gcsafe, raises: [], tags: [], forbids: [].}
Clears the request queue, unblocking any threads waiting on responses. All queued requests are completed with an error. Source   Edit  
proc close(curl: Curly) {....raises: [], tags: [], forbids: [].}
Blocks until all in-flight and queued requests complete, then closes all libcurl handles and deallocates the Curly object. Source   Edit  
proc close(pool: CurlPool) {....raises: [], tags: [], forbids: [].}
Closes the libcurl handles then deallocates the pool. All libcurl handles should be returned to the pool before it is closed. Source   Edit  
proc close(stream: ResponseStream) {....gcsafe, raises: [], tags: [], forbids: [].}
Frees the resources held by the stream. This must be called when done with the stream. It is safe to call close at any time (either when fully read or before the stream has finished to terminate it). After close has been called on a stream it is not safe to call read or close again. Source   Edit  
proc delete(batch: var RequestBatch; url: sink string;
            headers: sink HttpHeaders = emptyHttpHeaders();
            tag: sink string = "") {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc delete(curl: Curly; url: string;
            headers: sink HttpHeaders = emptyHttpHeaders(); timeout = 60): Response {.
    ...raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Source   Edit  
proc delete(curl: PCurl; url: string; headers = emptyHttpHeaders();
            timeout: float32 = 60.0): Response {.
    ...raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Source   Edit  
proc delete(pool: CurlPool; url: string; headers = emptyHttpHeaders();
            timeout: float32 = 60.0): Response {.
    ...raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Source   Edit  
proc get(batch: var RequestBatch; url: sink string;
         headers: sink HttpHeaders = emptyHttpHeaders(); tag: sink string = "") {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc get(curl: Curly; url: sink string;
         headers: sink HttpHeaders = emptyHttpHeaders(); timeout = 60): Response {.
    ...raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Source   Edit  
proc get(curl: PCurl; url: string; headers = emptyHttpHeaders();
         timeout: float32 = 60.0): Response {.
    ...raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Source   Edit  
proc get(pool: CurlPool; url: string; headers = emptyHttpHeaders();
         timeout: float32 = 60.0): Response {.
    ...raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Source   Edit  
proc hasRequests(curl: Curly): bool {....gcsafe, raises: [], tags: [], forbids: [].}
Returns true if there are requests in-flight or queued. Source   Edit  
proc head(batch: var RequestBatch; url: sink string;
          headers: sink HttpHeaders = emptyHttpHeaders(); tag: sink string = "") {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc head(curl: Curly; url: string;
          headers: sink HttpHeaders = emptyHttpHeaders(); timeout = 60): Response {.
    ...raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Source   Edit  
proc head(curl: PCurl; url: string; headers = emptyHttpHeaders();
          timeout: float32 = 60.0): Response {.
    ...raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Source   Edit  
proc head(pool: CurlPool; url: string; headers = emptyHttpHeaders();
          timeout: float32 = 60.0): Response {.
    ...raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Source   Edit  
proc len(batch: RequestBatch): int {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc makeRequest(curl: Curly; verb: sink string; url: sink string;
                 headers: sink HttpHeaders = emptyHttpHeaders();
                 body: openArray[char] = "".toOpenArray(0, -1); timeout = 60): Response {.
    ...gcsafe, raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Makes the HTTP request and blocks until the response is received. If a response cannot be received (due to timeout, DNS failure, broken connection, etc), an exception is raised. Source   Edit  
proc makeRequest(curl: PCurl; verb: string; url: string;
                 headers = emptyHttpHeaders();
                 body: openArray[char] = "".toOpenArray(0, -1);
                 timeout: float32 = 60.0): Response {.
    ...raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Source   Edit  
proc makeRequests(curl: Curly; batch: RequestBatch; timeout = 60): ResponseBatch {.
    ...raises: [], gcsafe, tags: [], forbids: [].}
Make multiple HTTP requests in parallel. This proc blocks until all requests have either received a response or are unable to complete. The return value seq is in the same order as the request batch. Each request will have either a response or an error in the return seq. If error != "" then something prevented the request from completing. This may be a timeout, DNS error, connection interruption, etc. The error string provides more information. Source   Edit  
proc newCurlPool(size: int): CurlPool {....raises: [Exception], tags: [],
                                        forbids: [].}
Creates a new thead-safe pool of libcurl handles. Source   Edit  
proc newCurly(maxInFlight = 16): Curly {....raises: [ResourceExhaustedError],
    tags: [], forbids: [].}
Creates a new Curly instance that will run up to maxInFlight HTTP requests in parallel. Source   Edit  
proc numInFlight(curl: Curly): int {....gcsafe, raises: [], tags: [], forbids: [].}
Returns the number of requests currently in-flight. Source   Edit  
proc patch(batch: var RequestBatch; url: sink string;
           headers: sink HttpHeaders = emptyHttpHeaders();
           body: sink string = ""; tag: sink string = "") {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc patch(curl: Curly; url: string;
           headers: sink HttpHeaders = emptyHttpHeaders();
           body: openArray[char] = "".toOpenArray(0, -1); timeout = 60): Response {.
    ...raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Source   Edit  
proc patch(curl: PCurl; url: string; headers = emptyHttpHeaders();
           body: openArray[char] = "".toOpenArray(0, -1);
           timeout: float32 = 60.0): Response {.
    ...raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Source   Edit  
proc patch(pool: CurlPool; url: string; headers = emptyHttpHeaders();
           body: openArray[char] = "".toOpenArray(0, -1);
           timeout: float32 = 60.0): Response {.
    ...raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Source   Edit  
proc pollForResponse(curl: Curly): Option[RequestResult] {....raises: [], gcsafe,
    tags: [], forbids: [].}
Returns a response to an HTTP request started by either startRequest or startRequests if one is available. Responses returned by this proc are in the order the responses are received, NOT in the order the requests were started. Source   Edit  
proc post(batch: var RequestBatch; url: sink string;
          headers: sink HttpHeaders = emptyHttpHeaders();
          body: sink string = ""; tag: sink string = "") {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc post(curl: Curly; url: string;
          headers: sink HttpHeaders = emptyHttpHeaders();
          body: openArray[char] = "".toOpenArray(0, -1); timeout = 60): Response {.
    ...raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Source   Edit  
proc post(curl: PCurl; url: string; headers = emptyHttpHeaders();
          body: openArray[char] = "".toOpenArray(0, -1); timeout: float32 = 60.0): Response {.
    ...raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Source   Edit  
proc post(pool: CurlPool; url: string; headers = emptyHttpHeaders();
          body: openArray[char] = "".toOpenArray(0, -1); timeout: float32 = 60.0): Response {.
    ...raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Source   Edit  
proc put(batch: var RequestBatch; url: sink string;
         headers: sink HttpHeaders = emptyHttpHeaders(); body: sink string = "";
         tag: sink string = "") {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc put(curl: Curly; url: string;
         headers: sink HttpHeaders = emptyHttpHeaders();
         body: openArray[char] = "".toOpenArray(0, -1); timeout = 60): Response {.
    ...raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Source   Edit  
proc put(curl: PCurl; url: string; headers = emptyHttpHeaders();
         body: openArray[char] = "".toOpenArray(0, -1); timeout: float32 = 60.0): Response {.
    ...raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Source   Edit  
proc put(pool: CurlPool; url: string; headers = emptyHttpHeaders();
         body: openArray[char] = "".toOpenArray(0, -1); timeout: float32 = 60.0): Response {.
    ...raises: [ZippyError, CatchableError], tags: [], forbids: [].}
Source   Edit  
proc queueLen(curl: Curly): int {....gcsafe, raises: [], tags: [], forbids: [].}
Returns the number of queued requests. Source   Edit  
proc read(stream: ResponseStream; buffer: var string): int {....gcsafe,
    raises: [CatchableError], tags: [], forbids: [].}
Adds new bytes received to buffer. Returns how many bytes were added. Blocks until bytes are received, an error occurs or the stream is finished. Source   Edit  
proc recycle(pool: CurlPool; handle: PCurl) {.inline, ...raises: [], gcsafe,
    tags: [], forbids: [].}
Returns a libcurl handle to the pool. Source   Edit  
proc request(curl: Curly; verb: sink string; url: sink string;
             headers: sink HttpHeaders = emptyHttpHeaders();
             body: openArray[char] = "".toOpenArray(0, -1); timeout = 60): ResponseStream {.
    ...gcsafe, raises: [CatchableError], tags: [], forbids: [].}
Starts a new HTTP request with a streamed response body. When this proc returns, the status code and headers are available. The response body should then be received by calls to read until the stream is finished. The timeout parameter is the maximum amount of time to spend waiting for this call to return. The timeout counter is then reset for each read call and is the maximum amount of time waiting for a read call to return. Remember to call close on the return value of this proc when you are done with it. Source   Edit  
proc startRequest(curl: Curly; verb: sink string; url: sink string;
                  headers: sink HttpHeaders = emptyHttpHeaders();
                  body: sink string = ""; timeout = 60; tag: sink string = "") {.
    ...raises: [], gcsafe, tags: [], forbids: [].}
Starts an HTTP request. These requests are run in parallel. This proc does not block waiting for a response. NOTE: When the request completes, a response is stored until it is removed by a call to waitForResponse. If the responses are never removed, they will accumulate in memory. Source   Edit  
proc startRequests(curl: Curly; batch: sink RequestBatch; timeout = 60) {.
    ...raises: [], gcsafe, tags: [], forbids: [].}
Starts one or more HTTP requests. These requests are run in parallel. This proc does not block waiting for responses. NOTE: When each request completes, a response is stored until it is removed by a call to waitForResponse or pollForResponse. If the responses are never removed, they will accumulate in memory. Source   Edit  
proc waitForResponse(curl: Curly): tuple[response: Response, error: string] {.
    ...raises: [], gcsafe, tags: [], forbids: [].}
Blocks waiting for a response to an HTTP request started by either startRequest or startRequests. Responses returned by this proc are in the order the responses are received, NOT in the order the requests were started. Source   Edit  

Templates

template withHandle(pool: CurlPool; handle, body)
Source   Edit