Request
struct Request
An outgoing HTTP request.
[src]
pub fn new(method: Method, uri: Uri | string): Request throws InvalidUriError {
let uri_: Uri;
switch (let uri = uri.(type)) {
case Uri:
uri_ = uri;
case string:
uri_ = try Uri.parse(uri);
}
return Request {
base: HttpRequest {
method: method,
uri: uri_,
headers: Headers.new(),
body: nil,
},
create_body: nil,
};
}
Creates a new HTTP request.
[src]
pub fn new(method: Method, uri: Uri | string): Request throws InvalidUriError {
let uri_: Uri;
switch (let uri = uri.(type)) {
case Uri:
uri_ = uri;
case string:
uri_ = try Uri.parse(uri);
}
return Request {
base: HttpRequest {
method: method,
uri: uri_,
headers: Headers.new(),
body: nil,
},
create_body: nil,
};
}
Creates a new HTTP request.
Creates a new HTTP request.
Example
use std.net.http.client.Request;
use std.net.http.Method;
fn main() throws {
let req = try Request.new(Method.Get, "https://example.com");
}
get
pub fn get(uri: Uri | string): Request throws InvalidUriError
[src]
pub fn get(uri: Uri | string): Request throws InvalidUriError {
return try Request.new(Method.Get, uri);
}
Creates a new HTTP request with the GET method.
get
pub fn get(uri: Uri | string): Request throws InvalidUriError
[src]
pub fn get(uri: Uri | string): Request throws InvalidUriError {
return try Request.new(Method.Get, uri);
}
Creates a new HTTP request with the GET method.
Creates a new HTTP request with the GET method.
post
pub fn post(uri: Uri | string): Request throws InvalidUriError
[src]
pub fn post(uri: Uri | string): Request throws InvalidUriError {
return try Request.new(Method.Post, uri);
}
Creates a new HTTP request with the POST method.
post
pub fn post(uri: Uri | string): Request throws InvalidUriError
[src]
pub fn post(uri: Uri | string): Request throws InvalidUriError {
return try Request.new(Method.Post, uri);
}
Creates a new HTTP request with the POST method.
Creates a new HTTP request with the POST method.
put
pub fn put(uri: Uri | string): Request throws InvalidUriError
[src]
pub fn put(uri: Uri | string): Request throws InvalidUriError {
return try Request.new(Method.Put, uri);
}
Creates a new HTTP request with the PUT method.
put
pub fn put(uri: Uri | string): Request throws InvalidUriError
[src]
pub fn put(uri: Uri | string): Request throws InvalidUriError {
return try Request.new(Method.Put, uri);
}
Creates a new HTTP request with the PUT method.
Creates a new HTTP request with the PUT method.
delete
pub fn delete(uri: Uri | string): Request throws InvalidUriError
[src]
pub fn delete(uri: Uri | string): Request throws InvalidUriError {
return try Request.new(Method.Delete, uri);
}
Creates a new HTTP request with the DELETE method.
delete
pub fn delete(uri: Uri | string): Request throws InvalidUriError
[src]
pub fn delete(uri: Uri | string): Request throws InvalidUriError {
return try Request.new(Method.Delete, uri);
}
Creates a new HTTP request with the DELETE method.
Creates a new HTTP request with the DELETE method.
head
pub fn head(uri: Uri | string): Request throws InvalidUriError
[src]
pub fn head(uri: Uri | string): Request throws InvalidUriError {
return try Request.new(Method.Head, uri);
}
Creates a new HTTP request with the HEAD method.
head
pub fn head(uri: Uri | string): Request throws InvalidUriError
[src]
pub fn head(uri: Uri | string): Request throws InvalidUriError {
return try Request.new(Method.Head, uri);
}
Creates a new HTTP request with the HEAD method.
Creates a new HTTP request with the HEAD method.
options
pub fn options(uri: Uri | string): Request throws InvalidUriError
[src]
pub fn options(uri: Uri | string): Request throws InvalidUriError {
return try Request.new(Method.Options, uri);
}
Creates a new HTTP request with the OPTIONS method.
options
pub fn options(uri: Uri | string): Request throws InvalidUriError
[src]
pub fn options(uri: Uri | string): Request throws InvalidUriError {
return try Request.new(Method.Options, uri);
}
Creates a new HTTP request with the OPTIONS method.
Creates a new HTTP request with the OPTIONS method.
connect
pub fn connect(uri: Uri | string): Request throws InvalidUriError
[src]
pub fn connect(uri: Uri | string): Request throws InvalidUriError {
return try Request.new(Method.Connect, uri);
}
Creates a new HTTP request with the CONNECT method.
connect
pub fn connect(uri: Uri | string): Request throws InvalidUriError
[src]
pub fn connect(uri: Uri | string): Request throws InvalidUriError {
return try Request.new(Method.Connect, uri);
}
Creates a new HTTP request with the CONNECT method.
Creates a new HTTP request with the CONNECT method.
patch
pub fn patch(uri: Uri | string): Request throws InvalidUriError
[src]
pub fn patch(uri: Uri | string): Request throws InvalidUriError {
return try Request.new(Method.Patch, uri);
}
Creates a new HTTP request with the PATCH method.
patch
pub fn patch(uri: Uri | string): Request throws InvalidUriError
[src]
pub fn patch(uri: Uri | string): Request throws InvalidUriError {
return try Request.new(Method.Patch, uri);
}
Creates a new HTTP request with the PATCH method.
Creates a new HTTP request with the PATCH method.
trace
pub fn trace(uri: Uri | string): Request throws InvalidUriError
[src]
pub fn trace(uri: Uri | string): Request throws InvalidUriError {
return try Request.new(Method.Trace, uri);
}
Creates a new HTTP request with the TRACE method.
trace
pub fn trace(uri: Uri | string): Request throws InvalidUriError
[src]
pub fn trace(uri: Uri | string): Request throws InvalidUriError {
return try Request.new(Method.Trace, uri);
}
Creates a new HTTP request with the TRACE method.
Creates a new HTTP request with the TRACE method.
[src]
pub fn headers(self): Headers {
return self.base.headers;
}
Returns the headers of the request.
[src]
pub fn headers(self): Headers {
return self.base.headers;
}
Returns the headers of the request.
Returns the headers of the request.
set_headers
pub fn set_headers(self, headers: Headers | <string, string>): Request
[src]
pub fn set_headers(self, headers: Headers | <string, string>): Request {
switch (let headers = headers.(type)) {
case Headers:
self.base.headers = headers;
case <string, string>:
self.base.headers = Headers.from_map(headers);
}
return self;
}
Sets the headers for the request.
set_headers
pub fn set_headers(self, headers: Headers | <string, string>): Request
[src]
pub fn set_headers(self, headers: Headers | <string, string>): Request {
switch (let headers = headers.(type)) {
case Headers:
self.base.headers = headers;
case <string, string>:
self.base.headers = Headers.from_map(headers);
}
return self;
}
Sets the headers for the request.
Sets the headers for the request.
set_header
pub fn set_header(self, key: string, value: string): Request
[src]
pub fn set_header(self, key: string, value: string): Request {
self.base.headers.set(key, value);
return self;
}
Sets the header for the request.
set_header
pub fn set_header(self, key: string, value: string): Request
[src]
pub fn set_header(self, key: string, value: string): Request {
self.base.headers.set(key, value);
return self;
}
Sets the header for the request.
Sets the header for the request.
append_header
pub fn append_header(self, key: string, value: string): Request
[src]
pub fn append_header(self, key: string, value: string): Request {
self.base.headers.append(key, value);
return self;
}
Appends the header for the request.
append_header
pub fn append_header(self, key: string, value: string): Request
[src]
pub fn append_header(self, key: string, value: string): Request {
self.base.headers.append(key, value);
return self;
}
Appends the header for the request.
Appends the header for the request.
set_query
pub fn set_query<T>(self, value: T): Request throws QsError, InvalidUriError
[src]
pub fn set_query<T>(self, value: T): Request throws querystring.QsError, InvalidUriError {
let qs = try querystring.to_string(value);
try self.base.uri.set_query(qs);
return self;
}
Sets the query string for the request.
set_query
pub fn set_query<T>(self, value: T): Request throws QsError, InvalidUriError
[src]
pub fn set_query<T>(self, value: T): Request throws querystring.QsError, InvalidUriError {
let qs = try querystring.to_string(value);
try self.base.uri.set_query(qs);
return self;
}
Sets the query string for the request.
Sets the query string for the request.
Example
use std.net.http.client.Request;
fn main() throws {
let req = try Request.get("https://example.com")
.set_query({ "key1": "value1", "key2": "value2" });
}
set_content_type
pub fn set_content_type(self, value: string): Request
[src]
pub fn set_content_type(self, value: string): Request {
self.base.headers.set("content-type", value);
return self;
}
Sets the content type for the request.
set_content_type
pub fn set_content_type(self, value: string): Request
[src]
pub fn set_content_type(self, value: string): Request {
self.base.headers.set("content-type", value);
return self;
}
Sets the content type for the request.
Sets the content type for the request.
Example
use std.net.http.client.Request;
fn main() throws {
let req = try Request.post("https://example.com")
.set_text("<a>123</a>")
.set_content_type("text/html");
}
set_content_length
pub fn set_content_length(self, value: int): Request
[src]
pub fn set_content_length(self, value: int): Request {
self.base.headers.set("content-length", `${value}`);
return self;
}
Sets the content length for the request.
set_content_length
pub fn set_content_length(self, value: int): Request
[src]
pub fn set_content_length(self, value: int): Request {
self.base.headers.set("content-length", `${value}`);
return self;
}
Sets the content length for the request.
Sets the content length for the request.
Usually does not need to be specifiy it directly.
[src]
pub fn set_body(self, body: ReadClose?): Request {
self.base.body = body;
return self;
}
Sets a body for the request.
[src]
pub fn set_body(self, body: ReadClose?): Request {
self.base.body = body;
return self;
}
Sets a body for the request.
Sets a body for the request.
Example
use std.net.http.client.Request;
use std.fs.File;
fn main() throws {
let req = try Request.post("https://example.com")
.set_body(File.open("file.txt"));
}
set_create_body_func
pub fn set_create_body_func(self, body: |()|: ReadClose??): Request
[src]
pub fn set_create_body_func(self, body: |(): ReadClose? throws|?): Request {
self.create_body = body;
return self;
}
Sets a closure to create a body for the request when a redirect requires reading the body more than once.
set_create_body_func
pub fn set_create_body_func(self, body: |()|: ReadClose??): Request
[src]
pub fn set_create_body_func(self, body: |(): ReadClose? throws|?): Request {
self.create_body = body;
return self;
}
Sets a closure to create a body for the request when a redirect requires reading the body more than once.
Sets a closure to create a body for the request when a redirect requires reading the body more than once.
NOTE: The first request still requires setting the body.
[src]
pub fn set_text(self, value: string): Request {
self.base.headers.set("content-type", mime.TEXT_PLAIN.to_string());
self.base.body = Cursor.new(value);
self.set_content_length(value.len());
return self;
}
Sets a text body for the request, and also sets the Content-Type: text/plain
header.
[src]
pub fn set_text(self, value: string): Request {
self.base.headers.set("content-type", mime.TEXT_PLAIN.to_string());
self.base.body = Cursor.new(value);
self.set_content_length(value.len());
return self;
}
Sets a text body for the request, and also sets the Content-Type: text/plain
header.
Sets a text body for the request, and also sets the Content-Type: text/plain
header.
[src]
pub fn set_bytes(self, value: Bytes): Request {
self.base.headers.set("content-type", "application/octet-stream");
self.base.body = Cursor.new(value);
self.set_content_length(value.len());
return self;
}
Sets a bytes body for the request, and also sets the Content-Type: application/octet-stream
header.
[src]
pub fn set_bytes(self, value: Bytes): Request {
self.base.headers.set("content-type", "application/octet-stream");
self.base.body = Cursor.new(value);
self.set_content_length(value.len());
return self;
}
Sets a bytes body for the request, and also sets the Content-Type: application/octet-stream
header.
Sets a bytes body for the request, and also sets the Content-Type: application/octet-stream
header.
[src]
pub fn set_json<T>(self, value: T): Request throws json.JsonError {
let data = try json.to_string(value);
self.base.headers.set("content-type", "application/json");
self.base.body = Cursor.new(data);
self.set_content_length(data.len());
return self;
}
Sets a JSON body for the request, and also sets the Content-Type: application/json
header.
[src]
pub fn set_json<T>(self, value: T): Request throws json.JsonError {
let data = try json.to_string(value);
self.base.headers.set("content-type", "application/json");
self.base.body = Cursor.new(data);
self.set_content_length(data.len());
return self;
}
Sets a JSON body for the request, and also sets the Content-Type: application/json
header.
Sets a JSON body for the request, and also sets the Content-Type: application/json
header.
Example
use std.net.http.client.Request;
fn main() throws {
let req = try Request.post("https://example.com")
.set_json({ "key1": "value1", "key2": "value2" });
}
[src]
pub fn set_form<T>(self, value: T): Request throws querystring.QsError {
let data = try querystring.to_string(value);
self.base.headers.set("content-type", "application/x-www-form-urlencoded");
self.base.body = Cursor.new(data);
self.set_content_length(data.len());
return self;
}
Sets a application/x-www-form-urlencoded
body for the request, and also sets
the Content-Type: application/x-www-form-urlencoded
header.
[src]
pub fn set_form<T>(self, value: T): Request throws querystring.QsError {
let data = try querystring.to_string(value);
self.base.headers.set("content-type", "application/x-www-form-urlencoded");
self.base.body = Cursor.new(data);
self.set_content_length(data.len());
return self;
}
Sets a application/x-www-form-urlencoded
body for the request, and also sets
the Content-Type: application/x-www-form-urlencoded
header.
Sets a application/x-www-form-urlencoded
body for the request, and also sets
the Content-Type: application/x-www-form-urlencoded
header.
Example
use std.net.http.client.Request;
fn main() throws {
let req = try Request.post("https://example.com")
.set_form({ "key1": "value1", "key2": "value2" });
}
set_multipart
pub fn set_multipart(self, value: Multipart): Request
[src]
pub fn set_multipart(self, value: Multipart): Request {
self.base.headers.set("content-type", `multipart/form-data; boundary=${value.boundary()}`);
if (let content_length = (value as _Multipart).content_length()) {
self.set_content_length(content_length);
}
self.base.body = (value as _Multipart).reader().to_nop_read_close();
return self;
}
Sets a multipart/form-data
body for the request, and also sets the Content-Type: multipart/form-data
header.
set_multipart
pub fn set_multipart(self, value: Multipart): Request
[src]
pub fn set_multipart(self, value: Multipart): Request {
self.base.headers.set("content-type", `multipart/form-data; boundary=${value.boundary()}`);
if (let content_length = (value as _Multipart).content_length()) {
self.set_content_length(content_length);
}
self.base.body = (value as _Multipart).reader().to_nop_read_close();
return self;
}
Sets a multipart/form-data
body for the request, and also sets the Content-Type: multipart/form-data
header.
Sets a multipart/form-data
body for the request, and also sets the Content-Type: multipart/form-data
header.
Example
use std.net.http.client.{Request, Multipart};
use std.fs.File;
fn main() throws {
let multipart = try Multipart.new()
.append("Hello, world!", name: "title")
.append(File.open("file.txt"), name: "file", content_type: "text/plain", file_name: "file.txt");
let req = try Request.post("https://example.com")
.set_multipart(multipart);
}