A set of HTTP headers
Example
use std.net.http.Headers;
let headers = Headers.new();
headers.set("host", "example.com");
headers.set("content-length", "1234");
assert headers.contains_key("host");
assert_eq headers.get("host"), "example.com";
assert headers.contains_key("content-length");
assert_eq headers.get("content-length"), "1234";
assert_eq headers.len(), 2;
[src]
pub fn to_string(self): string {
return (self as _Headers).to_string();
}
[src]
pub fn to_string(self): string {
return (self as _Headers).to_string();
}
[src]
pub fn new(): Headers {
return _Headers.new() as Headers;
}
Create an empty Headers
.
[src]
pub fn new(): Headers {
return _Headers.new() as Headers;
}
Create an empty Headers
.
Create an empty Headers
.
Example
use std.net.http.Headers;
let headers = Headers.new();
[src]
pub fn from_map(headers: <string, string>): Headers {
let new_headers = Headers.new();
for (let key, val in headers) {
new_headers.set(key, val);
}
return new_headers;
}
Create a Headers
from a map.
[src]
pub fn from_map(headers: <string, string>): Headers {
let new_headers = Headers.new();
for (let key, val in headers) {
new_headers.set(key, val);
}
return new_headers;
}
Create a Headers
from a map.
Create a Headers
from a map.
Example
use std.net.http.Headers;
let headers = Headers.from_map({
"host": "example.com",
"content-length": "1234"
});
assert headers.contains_key("host");
assert_eq headers.get("host"), "example.com";
assert headers.contains_key("content-length");
assert_eq headers.get("content-length"), "1234";
set_sensitive
pub fn set_sensitive(self, key: string)
[src]
pub fn set_sensitive(self, key: string) {
(self as _Headers).set_sensitive(key, true);
}
Mark that the header value represents sensitive information.
set_sensitive
pub fn set_sensitive(self, key: string)
[src]
pub fn set_sensitive(self, key: string) {
(self as _Headers).set_sensitive(key, true);
}
Mark that the header value represents sensitive information.
Mark that the header value represents sensitive information.
Sensitive data could represent passwords or other data that should not be stored on disk or in memory. By marking header values as sensitive, components using this crate can be instructed to treat them with special care for security reasons. For example, caches can avoid storing sensitive values, and HPACK encoders used by HTTP/2.0 implementations can choose not to compress them.
Additionally, sensitive values will be masked by the ToString
implementation.
Note that sensitivity is not factored into equality or ordering.
Example
use std.net.http.Headers;
let headers = Headers.new();
headers.set("authorization", "my secret");
headers.set_sensitive("authorization");
headers.set("host", "example.com");
assert_eq headers.to_string(), "host: example.com\r\n";
set_insensitive
pub fn set_insensitive(self, key: string)
[src]
pub fn set_insensitive(self, key: string) {
(self as _Headers).set_sensitive(key, false);
}
Mark that the header value does not represent sensitive information.
set_insensitive
pub fn set_insensitive(self, key: string)
[src]
pub fn set_insensitive(self, key: string) {
(self as _Headers).set_sensitive(key, false);
}
Mark that the header value does not represent sensitive information.
Mark that the header value does not represent sensitive information.
[src]
pub fn get(self, key: string): string? {
return (self as _Headers).get(key);
}
Returns the first value for the header with the given name.
[src]
pub fn get(self, key: string): string? {
return (self as _Headers).get(key);
}
Returns the first value for the header with the given name.
Returns the first value for the header with the given name.
Example
use std.net.http.Headers;
let headers = Headers.new();
headers.set("host", "example.com");
assert_eq headers.get("host"), "example.com";
[src]
pub fn get_all(self, name: string): [string] {
let items: [string] = [];
let name = name.to_lowercase();
(self as _Headers).iter(|key, value| {if (name == key.to_lowercase()) {items.push(value);}});
return items;
}
Returns all values for the header with the given name.
[src]
pub fn get_all(self, name: string): [string] {
let items: [string] = [];
let name = name.to_lowercase();
(self as _Headers).iter(|key, value| {if (name == key.to_lowercase()) {items.push(value);}});
return items;
}
Returns all values for the header with the given name.
Returns all values for the header with the given name.
Example
use std.net.http.Headers;
let headers = Headers.new();
headers.append("set-cookie", "theme=light");
headers.append("set-cookie", "session");
assert_eq headers.get_all("set-cookie"), ["theme=light", "session"];
[src]
pub fn set(self, key: string, value: string) {
(self as _Headers).set(key, value);
}
Set the header with the given name to the given value.
[src]
pub fn set(self, key: string, value: string) {
(self as _Headers).set(key, value);
}
Set the header with the given name to the given value.
Set the header with the given name to the given value.
If a header with the same name already exists, it is replaced with the new value.
Example
use std.net.http.Headers;
let headers = Headers.new();
headers.set("host", "example.com");
assert_eq headers.get("host"), "example.com";
[src]
pub fn append(self, key: string, value: string) {
(self as _Headers).append(key, value);
}
Append a value to the header with the given name.
[src]
pub fn append(self, key: string, value: string) {
(self as _Headers).append(key, value);
}
Append a value to the header with the given name.
Append a value to the header with the given name.
Append a new value, it will not replace the existing value.
Example
use std.net.http.Headers;
let headers = Headers.new();
headers.append("set-cookie", "theme=light");
headers.append("set-cookie", "session");
assert_eq headers.get_all("set-cookie"), ["theme=light", "session"];
[src]
pub fn remove(self, key: string) {
(self as _Headers).remove(key);
}
Remove the header with the given name.
[src]
pub fn remove(self, key: string) {
(self as _Headers).remove(key);
}
Remove the header with the given name.
Remove the header with the given name.
Example
use std.net.http.Headers;
let headers = Headers.new();
headers.set("host", "example.com");
headers.remove("host");
assert_eq headers.len(), 0;
[src]
pub fn keys(self): [string] {
let keys: [string] = [];
(self as _Headers).iter(|key, value| keys.push(key));
return keys;
}
Returns all header names as array of strings.
[src]
pub fn keys(self): [string] {
let keys: [string] = [];
(self as _Headers).iter(|key, value| keys.push(key));
return keys;
}
Returns all header names as array of strings.
Returns all header names as array of strings.
Example
use std.net.http.Headers;
let headers = Headers.new();
headers.set("host", "example.com");
headers.set("content-length", "1234");
headers.set("host", "abc.com");
assert_eq headers.keys(), ["host", "content-length"];
[src]
pub fn len(self): int {
return (self as _Headers).len();
}
Returns the number of headers.
[src]
pub fn len(self): int {
return (self as _Headers).len();
}
Returns the number of headers.
Returns the number of headers.
Example
use std.net.http.Headers;
let headers = Headers.new();
headers.set("host", "example.com");
headers.set("content-length", "1234");
assert_eq headers.len(), 2;
[src]
pub fn is_empty(self): bool {
return self.len() == 0;
}
Returns true
if the headers is empty.
[src]
pub fn is_empty(self): bool {
return self.len() == 0;
}
Returns true
if the headers is empty.
Returns true
if the headers is empty.
Example
use std.net.http.Headers;
let headers = Headers.new();
assert headers.is_empty();
headers.set("host", "example.com");
assert !headers.is_empty();
contains_key
pub fn contains_key(self, key: string): bool
[src]
pub fn contains_key(self, key: string): bool {
return (self as _Headers).contains_key(key);
}
Returns true
if the header with the given name exists.
contains_key
pub fn contains_key(self, key: string): bool
[src]
pub fn contains_key(self, key: string): bool {
return (self as _Headers).contains_key(key);
}
Returns true
if the header with the given name exists.
Returns true
if the header with the given name exists.
Example
use std.net.http.Headers;
let headers = Headers.new();
headers.set("host", "example.com");
assert headers.contains_key("host");
assert !headers.contains_key("content-length");
[src]
pub fn extend(self, other: Headers) {
(self as _Headers).extend(other as _Headers);
}
Append the headers from another Headers
object.
[src]
pub fn extend(self, other: Headers) {
(self as _Headers).extend(other as _Headers);
}
Append the headers from another Headers
object.
Append the headers from another Headers
object.
Example
use std.net.http.Headers;
let headers = Headers.new();
headers.set("host", "example.com");
let other = Headers.new();
other.set("content-length", "1234");
headers.extend(other);
assert headers.contains_key("host");
assert headers.contains_key("content-length");
[src]
pub fn clone(self): Headers {
return (self as _Headers).clone() as Headers;
}
Clone the headers.
[src]
pub fn clone(self): Headers {
return (self as _Headers).clone() as Headers;
}
Clone the headers.
Clone the headers.
Example
use std.net.http.Headers;
let headers = Headers.new();
headers.set("host", "example.com");
let cloned = headers.clone();
assert_eq headers.to_string(), cloned.to_string();
cloned.set("content-length", "1234");
assert !headers.contains_key("content-length");
assert cloned.contains_key("content-length");