pub struct Request<'a> { /* private fields */ }
Expand description
Builder structure for an HTTP request.
This is the primary API-type in crimp
. After creating a new
request its parameters are modified using the various builder
methods until it is consumed by send()
.
Implementations
sourceimpl<'a> Request<'a>
impl<'a> Request<'a>
sourcepub fn user_agent(self, agent: &str) -> Result<Self, Error>
pub fn user_agent(self, agent: &str) -> Result<Self, Error>
Set the User-Agent
for this request. By default this will be
set to cURL’s standard user agent.
sourcepub fn bearer_auth(self, token: &str) -> Result<Self, Error>
pub fn bearer_auth(self, token: &str) -> Result<Self, Error>
Set the Authorization
header to a Bearer
value with the
supplied token.
sourcepub fn basic_auth(self, username: &str, password: &str) -> Result<Self, Error>
pub fn basic_auth(self, username: &str, password: &str) -> Result<Self, Error>
Set the Authorization
header to a basic authentication value
from the supplied username and password.
sourcepub fn tls_client_cert<P: AsRef<Path>>(
self,
cert_type: CertType,
cert: P
) -> Result<Self, Error>
pub fn tls_client_cert<P: AsRef<Path>>(
self,
cert_type: CertType,
cert: P
) -> Result<Self, Error>
Configure a TLS client certificate on the request.
Depending on whether the certificate file contains the private
key or not, calling tls_client_key
may be required in
addition.
Consult the documentation for the ssl_cert
and ssl_key
functions in curl::easy::Easy2
for details on supported
formats and defaults.
sourcepub fn tls_client_key<P: AsRef<Path>>(self, key: P) -> Result<Self, Error>
pub fn tls_client_key<P: AsRef<Path>>(self, key: P) -> Result<Self, Error>
Configure a TLS client certificate key on the request.
Note that this does not need to be called again for
PKCS12-encoded key pairs which are set via tls_client_cert
.
Currently only PEM-encoded key files are supported.
sourcepub fn tls_key_password(self, password: &str) -> Result<Self, Error>
pub fn tls_key_password(self, password: &str) -> Result<Self, Error>
Configure an encryption password for a TLS client certificate key on the request.
This is required in case of an encrypted private key that should be used.
sourcepub fn timeout(self, timeout: Duration) -> Result<Self, Error>
pub fn timeout(self, timeout: Duration) -> Result<Self, Error>
Configure a timeout for the request after which the request will be aborted.
sourcepub fn with_handle<F>(self, function: F) -> Result<Self, Error> where
F: FnOnce(&mut Easy) -> Result<(), Error>,
pub fn with_handle<F>(self, function: F) -> Result<Self, Error> where
F: FnOnce(&mut Easy) -> Result<(), Error>,
Set custom configuration on the cURL Easy
handle.
This function can be considered an “escape-hatch” from the
high-level API which lets users access the internal
curl::easy::Easy
handle and configure options on it
directly.
let response = Request::get("https://httpbin.org/get")
.with_handle(|mut handle| handle.referer("Example-Referer"))
.unwrap()
.send()
.unwrap();
sourcepub fn body(self, content_type: &'a str, data: &'a [u8]) -> Self
pub fn body(self, content_type: &'a str, data: &'a [u8]) -> Self
Add a byte-array body to a request using the specified
Content-Type
.
sourcepub fn form(self, form: Form) -> Self
pub fn form(self, form: Form) -> Self
Add a form-encoded body to a request using the curl::Form
type.
use curl::easy::Form;
let mut form = Form::new();
form.part("some-name")
.contents("some-data".as_bytes())
.add()
.unwrap();
let response = Request::post("https://httpbin.org/post")
.user_agent("crimp test suite")
.unwrap()
.form(form)
.send()
.unwrap();
See the documentation of curl::easy::Form
for details on how
to construct a form body.
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Request<'a>
impl<'a> !Send for Request<'a>
impl<'a> !Sync for Request<'a>
impl<'a> Unpin for Request<'a>
impl<'a> !UnwindSafe for Request<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more