Format function docs.

This commit is contained in:
jcamiel 2022-06-11 11:15:43 +02:00 committed by Fabrice Reix
parent e962de40b8
commit 79c2f2b9be
3 changed files with 20 additions and 35 deletions

View File

@ -40,9 +40,9 @@ pub struct CookieAttribute {
}
impl ResponseCookie {
/// Parses value from Set-Cookie header into a `ResponseCookie`.
///
/// parse value from Set-Cookie Header into a Cookie
///
/// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie
pub fn parse(s: String) -> Option<ResponseCookie> {
if let Some(index) = s.find('=') {
let (name, remaining) = s.split_at(index);
@ -63,9 +63,7 @@ impl ResponseCookie {
}
}
///
/// return the optional Expires attribute as String type
///
/// Returns the optional Expires attribute as `String` type.
pub fn expires(&self) -> Option<String> {
for attr in self.attributes.clone() {
if attr.name.as_str() == "Expires" {
@ -75,11 +73,9 @@ impl ResponseCookie {
None
}
/// Returns the optional Max-Age attribute as `i64` type.
///
/// return the optional max_age attribute as i64 type
///
/// if the value is not a valid integer, the attribute is simply ignored
///
/// If the value is not a valid integer, the attribute is simply ignored
pub fn max_age(&self) -> Option<i64> {
for attr in self.attributes.clone() {
if attr.name.as_str() == "Max-Age" {
@ -93,9 +89,7 @@ impl ResponseCookie {
None
}
///
/// return the optional Domain attribute as String type
///
/// Returns the optional Domain attribute as `String` type.
pub fn domain(&self) -> Option<String> {
for attr in self.attributes.clone() {
if attr.name.as_str() == "Domain" {
@ -105,9 +99,7 @@ impl ResponseCookie {
None
}
///
/// return the optional Path attribute as String type
///
/// Returns the optional Path attribute as `String` type.
pub fn path(&self) -> Option<String> {
for attr in self.attributes.clone() {
if attr.name.as_str() == "Path" {
@ -117,9 +109,7 @@ impl ResponseCookie {
None
}
///
/// return true if the Secure attribute is present
///
/// Return true if the Secure attribute is present.
pub fn has_secure(&self) -> bool {
for attr in self.attributes.clone() {
if attr.name.as_str() == "Secure" && attr.value.is_none() {
@ -129,9 +119,7 @@ impl ResponseCookie {
false
}
///
/// return true if the HttpOnly attribute is present
///
/// Return true if the HttpOnly attribute is present.
pub fn has_httponly(&self) -> bool {
for attr in self.attributes.clone() {
if attr.name.as_str() == "HttpOnly" && attr.value.is_none() {
@ -141,9 +129,7 @@ impl ResponseCookie {
false
}
///
/// return the optional SameSite attribute as String type
///
/// Returns the optional SameSite attribute as `String` type.
pub fn samesite(&self) -> Option<String> {
for attr in self.attributes.clone() {
if attr.name.as_str() == "SameSite" {

View File

@ -27,9 +27,7 @@ impl Response {
.collect()
}
///
/// Return option cookie from response
///
/// Returns optional cookies from response.
pub fn get_cookie(&self, name: String) -> Option<ResponseCookie> {
for cookie in self.cookies() {
if cookie.name == name {

View File

@ -18,9 +18,10 @@
use encoding::{DecoderTrap, EncodingRef};
///
/// Uncompress body response
/// Decompresses body response
/// using the Content-Encoding response header
///
/// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
use std::io::prelude::*;
use crate::http::{HttpError, Response};
@ -51,7 +52,7 @@ impl ContentEncoding {
}
}
/// Decompress bytes.
/// Decompresses bytes.
///
/// # Arguments
///
@ -83,7 +84,7 @@ impl Response {
}
}
/// Returns response body as text
/// Returns response body as text.
pub fn text(&self) -> Result<String, HttpError> {
let encoding = self.character_encoding()?;
let body = &self.uncompress_body()?;
@ -95,7 +96,7 @@ impl Response {
}
}
/// Returns true if response is an HTML response
/// Returns true if response is an HTML response.
pub fn is_html(&self) -> bool {
match self.content_type() {
None => false,
@ -105,7 +106,7 @@ impl Response {
/// Returns list of content encoding from HTTP response headers.
///
/// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
/// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
fn content_encoding(&self) -> Result<Vec<ContentEncoding>, HttpError> {
for header in &self.headers {
if header.name.as_str().to_ascii_lowercase() == "content-encoding" {
@ -131,7 +132,7 @@ impl Response {
}
}
/// Decompress Brotli compressed data.
/// Decompresses Brotli compressed data.
///
/// # Arguments
///
@ -148,7 +149,7 @@ fn uncompress_brotli(data: &[u8]) -> Result<Vec<u8>, HttpError> {
}
}
/// Decompress GZip compressed data.
/// Decompresses GZip compressed data.
///
/// # Arguments
///
@ -171,7 +172,7 @@ fn uncompress_gzip(data: &[u8]) -> Result<Vec<u8>, HttpError> {
}
}
/// Decompress Zlib compressed data.
/// Decompresses Zlib compressed data.
///
/// # Arguments
///