The OpenD Programming Language

requests.request

* This module provides API using Request structure. * * Structure Request provides configuration, connection pooling, cookie * persistance. You can consider it as 'Session' and reuse it - all caches and settings will effective * for next requests.

* Some most usefull settings:

nametypemeaningdefault
keepAlivebooluse keepalive connectiontrue
verbosityuintverbosity level (0, 1, 2 or 3)16KB
maxRedirectsuintmaximum redirects allowed (0 to disable redirects)true
maxHeadersLengthsize_tmax. acceptable response headers length32KB
maxContentLengthsize_tmax. acceptable content length0 - unlimited
bufferSizesize_tsocket io buffer size16KB
timeoutDurationtimeout on connect or data transfer30.seconds
proxystringurl of the HTTP/HTTPS/FTP proxynull
bindstringuse local address for outgoing connectionsnull
useStreamingboolreceive response data as InputRange in case it can't fit memoryfalse
addHeadersstring[string]custom headersnull
cookieCookie[]cookies you will send to servernull
authenticatorAuthauthenticatornull
socketFactorysee doc for socketFactoryuser-provided connection factorynull

* Example: * --- * import requests; * import std.datetime; * * void main() * { * Request rq = Request(); * Response rs; * rq.timeout = 10.seconds; * rq.addHeaders(["User-Agent": "unknown"]); * rs = rq.get("https://httpbin.org/get"); * assert(rs.code==200); * rs = rq.post("http://httpbin.org/post", "abc"); * assert(rs.code==200); * } * ---

Members

Functions

addInterceptor
void addInterceptor(Interceptor i)

* Add module-level interceptor. Each Request will include it in the processing. * it is handy as you can change behaviour of your requests without any changes * in your code, just install interceptor before any call to Request().

Interfaces

Interceptor
interface Interceptor

* 'Intercepror' intercepts Request. It can modify request, or log it, or cache it * or do whatever you need. When done it can return response or * pass it to next request handler. * * Example: * --- * class ChangePath : Interceptor * { * Response opCall(Request r, RequestHandler next) * { * r.path = r.path ~ "get"; * auto rs = next.handle(r); * return rs; * } * } * --- * Later in the code you can use this class: * Example: * --- * Request rq; * rq.addInterceptor(new ChangePath()); * rq.get("http://example.com"); * --- *

Structs

Request
struct Request

* Structure Request provides configuration, connection pooling, cookie * persistance. You can consider it as 'Session'.

Meta