1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-23 14:05:14 +02:00

big clean up and docs improvmenet of types mod (#1894)

This commit is contained in:
Rob Ede
2021-01-09 13:17:19 +00:00
committed by GitHub
parent 530d03791d
commit 6575ee93f2
22 changed files with 674 additions and 743 deletions

View File

@@ -481,15 +481,14 @@ impl ResponseBuilder {
self
}
/// Set response content type
/// Set response content type.
#[inline]
pub fn content_type<V>(&mut self, value: V) -> &mut Self
where
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
V: IntoHeaderValue,
{
if let Some(parts) = parts(&mut self.head, &self.err) {
match HeaderValue::try_from(value) {
match value.try_into() {
Ok(value) => {
parts.headers.insert(header::CONTENT_TYPE, value);
}
@@ -802,7 +801,7 @@ impl From<ResponseBuilder> for Response {
impl From<&'static str> for Response {
fn from(val: &'static str) -> Self {
Response::Ok()
.content_type("text/plain; charset=utf-8")
.content_type(mime::TEXT_PLAIN_UTF_8)
.body(val)
}
}
@@ -810,7 +809,7 @@ impl From<&'static str> for Response {
impl From<&'static [u8]> for Response {
fn from(val: &'static [u8]) -> Self {
Response::Ok()
.content_type("application/octet-stream")
.content_type(mime::APPLICATION_OCTET_STREAM)
.body(val)
}
}
@@ -818,7 +817,7 @@ impl From<&'static [u8]> for Response {
impl From<String> for Response {
fn from(val: String) -> Self {
Response::Ok()
.content_type("text/plain; charset=utf-8")
.content_type(mime::TEXT_PLAIN_UTF_8)
.body(val)
}
}
@@ -826,7 +825,7 @@ impl From<String> for Response {
impl<'a> From<&'a String> for Response {
fn from(val: &'a String) -> Self {
Response::Ok()
.content_type("text/plain; charset=utf-8")
.content_type(mime::TEXT_PLAIN_UTF_8)
.body(val)
}
}
@@ -834,7 +833,7 @@ impl<'a> From<&'a String> for Response {
impl From<Bytes> for Response {
fn from(val: Bytes) -> Self {
Response::Ok()
.content_type("application/octet-stream")
.content_type(mime::APPLICATION_OCTET_STREAM)
.body(val)
}
}
@@ -842,7 +841,7 @@ impl From<Bytes> for Response {
impl From<BytesMut> for Response {
fn from(val: BytesMut) -> Self {
Response::Ok()
.content_type("application/octet-stream")
.content_type(mime::APPLICATION_OCTET_STREAM)
.body(val)
}
}