pub struct HttpRequestBuilder<'a> { /* private fields */ }
Expand description
An HTTP request builder.
This type can be used to construct an instance of an HttpRequest using a builder-like pattern.
§Examples
use ic_http_certification::{HttpRequestBuilder, Method};
let request = HttpRequestBuilder::new()
.with_method(Method::GET)
.with_url("/")
.with_headers(vec![("X-Custom-Foo".into(), "Bar".into())])
.with_body(&[1, 2, 3])
.with_certificate_version(2)
.build();
assert_eq!(request.method(), Method::GET);
assert_eq!(request.url(), "/");
assert_eq!(request.headers(), &[("X-Custom-Foo".into(), "Bar".into())]);
assert_eq!(request.body(), &[1, 2, 3]);
assert_eq!(request.certificate_version(), Some(2));
Implementations§
Source§impl<'a> HttpRequestBuilder<'a>
impl<'a> HttpRequestBuilder<'a>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new instance of the HttpRequestBuilder that can be used to construct an HttpRequest.
§Examples
use ic_http_certification::{HttpRequestBuilder, Method};
let request = HttpRequestBuilder::new()
.with_method(Method::GET)
.with_url("/")
.with_headers(vec![("X-Custom-Foo".into(), "Bar".into())])
.with_body(&[1, 2, 3])
.with_certificate_version(2)
.build();
assert_eq!(request.method(), Method::GET);
assert_eq!(request.url(), "/");
assert_eq!(request.headers(), &[("X-Custom-Foo".into(), "Bar".into())]);
assert_eq!(request.body(), &[1, 2, 3]);
assert_eq!(request.certificate_version(), Some(2));
Sourcepub fn with_method(self, method: Method) -> Self
pub fn with_method(self, method: Method) -> Self
Set the HTTP method of the HttpRequest.
This function will accept both owned and borrowed values. By default,
the method will be set to "GET"
.
§Examples
use ic_http_certification::{HttpRequestBuilder, Method};
let request = HttpRequestBuilder::new()
.with_method(Method::GET)
.build();
assert_eq!(request.method(), Method::GET);
Sourcepub fn with_url(self, url: impl Into<String>) -> Self
pub fn with_url(self, url: impl Into<String>) -> Self
Set the HTTP URL of the HttpRequest.
This function will accept both owned and borrowed values. By default,
the URL will be set to "/"
.
§Examples
use ic_http_certification::HttpRequestBuilder;
let request = HttpRequestBuilder::new()
.with_url("/")
.build();
assert_eq!(request.url(), "/");
Sourcepub fn with_headers(self, headers: Vec<HeaderField>) -> Self
pub fn with_headers(self, headers: Vec<HeaderField>) -> Self
Set the HTTP headers of the HttpRequest.
By default the headers will be an empty array.
§Examples
use ic_http_certification::{HttpRequestBuilder, HeaderField};
let request = HttpRequestBuilder::new()
.with_headers(vec![("X-Custom-Foo".into(), "Bar".into())])
.build();
assert_eq!(request.headers(), &[("X-Custom-Foo".into(), "Bar".into())]);
Sourcepub fn with_body(self, body: impl Into<Cow<'a, [u8]>>) -> Self
pub fn with_body(self, body: impl Into<Cow<'a, [u8]>>) -> Self
Set the HTTP body of the HttpRequest.
This function will accept both owned and borrowed values. By default, the body will be an empty array.
§Examples
use ic_http_certification::HttpRequestBuilder;
let request = HttpRequestBuilder::new()
.with_body(&[1, 2, 3])
.build();
assert_eq!(request.body(), &[1, 2, 3]);
Sourcepub fn with_certificate_version(self, certificate_version: u16) -> Self
pub fn with_certificate_version(self, certificate_version: u16) -> Self
Set the max response verification vwersion to use in the crate::HttpResponse certificate.
By default, the certificate version will be None
, which
is equivalent to setting it to version 1
.
§Examples
use ic_http_certification::HttpRequestBuilder;
let request = HttpRequestBuilder::new()
.with_certificate_version(2)
.build();
assert_eq!(request.certificate_version(), Some(2));
Sourcepub fn build(self) -> HttpRequest<'a>
pub fn build(self) -> HttpRequest<'a>
Build an HttpRequest from the builder.
If the method is not set, it will default to "GET"
.
If the URL is not set, it will default to "/"
.
If the certificate version is not set, it will default to 1
.
If the headers or body are not set, they will default to empty arrays.
§Examples
use ic_http_certification::{HttpRequestBuilder, Method};
let request = HttpRequestBuilder::new()
.with_method(Method::GET)
.with_url("/")
.with_headers(vec![("X-Custom-Foo".into(), "Bar".into())])
.with_body(&[1, 2, 3])
.with_certificate_version(2)
.build();
assert_eq!(request.method(), Method::GET);
assert_eq!(request.url(), "/");
assert_eq!(request.headers(), &[("X-Custom-Foo".into(), "Bar".into())]);
assert_eq!(request.body(), &[1, 2, 3]);
assert_eq!(request.certificate_version(), Some(2));
Sourcepub fn build_update(self) -> HttpUpdateRequest<'a>
pub fn build_update(self) -> HttpUpdateRequest<'a>
Build an HttpUpdateRequest from the builder.
If the method is not set, it will default to "GET"
.
If the URL is not set, it will default to "/"
.
If the headers or body are not set, they will default to empty arrays.
§Examples
use ic_http_certification::{HttpRequestBuilder, Method};
let update_request = HttpRequestBuilder::new()
.with_method(Method::GET)
.with_url("/")
.with_headers(vec![("X-Custom-Foo".into(), "Bar".into())])
.with_body(&[1, 2, 3])
.build_update();
assert_eq!(update_request.method(), Method::GET);
assert_eq!(update_request.url(), "/");
assert_eq!(update_request.headers(), &[("X-Custom-Foo".into(), "Bar".into())]);
assert_eq!(update_request.body(), &[1, 2, 3]);
Trait Implementations§
Source§impl<'a> Clone for HttpRequestBuilder<'a>
impl<'a> Clone for HttpRequestBuilder<'a>
Source§fn clone(&self) -> HttpRequestBuilder<'a>
fn clone(&self) -> HttpRequestBuilder<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more