pub struct ResponseHeadRef<'a> {
pub status: u16,
pub fields: &'a [(&'a str, &'a [u8])],
pub body: OutgoingBody,
pub close: bool,
pub upgrade: Option<&'a str>,
}Expand description
A response head described with borrowed data, for
ServerConn::write_head: nothing is copied into an owned builder and
nothing is allocated.
The fields are validated when the head is written, with the same rules as
Response::header: token names, no framing or connection fields (the
connection writes those), no control bytes or surrounding whitespace in
values. A date field among them stops a date passed to write_head
from being added. upgrade names the protocol of a 101 Switching Protocols, as Response::switching_protocols does.
The struct is built with a literal, so its fields are public and it is
not #[non_exhaustive]; use ResponseHeadRef::new to start from the
defaults.
§Examples
use http_net::{OutgoingBody, ResponseHeadRef};
let fields: &[(&str, &[u8])] = &[("content-type", b"text/plain")];
let head = ResponseHeadRef {
status: 200,
fields,
body: OutgoingBody::Full(5),
close: false,
upgrade: None,
};
assert_eq!(head, ResponseHeadRef::new(200, fields, OutgoingBody::Full(5)));Fields§
§status: u16The status code (100..=599; among the 1xx codes only 101).
fields: &'a [(&'a str, &'a [u8])]The fields, in order, as (name, value).
body: OutgoingBodyHow the body is supplied.
close: boolClose the connection after this response.
upgrade: Option<&'a str>The protocol a 101 switches to.
Implementations§
Source§impl<'a> ResponseHeadRef<'a>
impl<'a> ResponseHeadRef<'a>
Sourcepub const fn new(
status: u16,
fields: &'a [(&'a str, &'a [u8])],
body: OutgoingBody,
) -> Self
pub const fn new( status: u16, fields: &'a [(&'a str, &'a [u8])], body: OutgoingBody, ) -> Self
A head with status, fields, and body; no close, no upgrade.
§Examples
use http_net::{OutgoingBody, ResponseHeadRef};
let head = ResponseHeadRef::new(204, &[], OutgoingBody::Empty);
assert!(!head.close);