id
stringlengths
20
30
source
stringclasses
1 value
chunk_index
int64
0
520k
token_count
int32
154
512
content
stringlengths
185
57.5k
rust_dataset_chunk_800
rust_dataset.txt
800
512
struct FromRequestOptFuture<Fut> { #[pin] fut: Fut, } } impl<Fut, T, E> Future for FromRequestOptFuture<Fut> where Fut: Future<Output = Result<T, E>>, E: Into<Error>, { type Output = Result<Option<T>, Infallible>; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::O...
rust_dataset_chunk_801
rust_dataset.txt
801
512
T: FromRequest, T::Error: Into<E>, { type Error = Infallible; type Future = FromRequestResFuture<T::Future, E>; #[inline] fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future { FromRequestResFuture { fut: T::from_request(req, payload), _phant...
rust_dataset_chunk_802
rust_dataset.txt
802
512
Error>>; fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future { ready(Ok(req.method().clone())) } } #[doc(hidden)] #[allow(non_snake_case)] mod tuple_from_req { use super::*; macro_rules! tuple_from_req { ($fut: ident; $($T: ident),*) => { /// FromRequest im...
rust_dataset_chunk_803
rust_dataset.txt
803
512
} } } }; } pin_project! { #[project = ExtractProj] #[project_replace = ExtractReplaceProj] enum ExtractFuture<Fut, Res> { Future { #[pin] fut: Fut }, Done { ...
rust_dataset_chunk_804
rust_dataset.txt
804
512
! { TupleFromRequest15; A, B, C, D, E, F, G, H, I, J, K, L, M, N, O } tuple_from_req! { TupleFromRequest16; A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P } } #[cfg(test)] mod tests { use actix_http::header; use bytes::Bytes; use serde::Deserialize; use super::*; use crate::{ test::Tes...
rust_dataset_chunk_805
rust_dataset.txt
805
512
header::CONTENT_TYPE, "application/x-www-form-urlencoded")) .insert_header((header::CONTENT_LENGTH, "11")) .set_payload(Bytes::from_static(b"hello=world")) .to_http_parts(); let r = Result::<Form<Info>, Error>::from_request(&req, &mut pl) .await .unwr...
rust_dataset_chunk_806
rust_dataset.txt
806
512
.path(), "/foo/bar"); assert_eq!( form, Form(Info { hello: "world".into() }) ); } } --- FILE: actix-web/actix-web/src/guard/acceptable.rs --- use super::{Guard, GuardContext}; use crate::http::header::Accept; /// A guard that verifies that an `A...
rust_dataset_chunk_807
rust_dataset.txt
807
512
}; } false } #[cfg(feature = "experimental-introspection")] fn name(&self) -> String { if self.match_star_star { format!("Acceptable({}, match_star_star=true)", self.mime) } else { format!("Acceptable({})", self.mime) } } ...
rust_dataset_chunk_808
rust_dataset.txt
808
512
); assert!(details.iter().any(|detail| match detail { crate::guard::GuardDetail::Generic(value) => value == &expected, _ => false, })); assert_eq!( guard.name(), format!( "Acceptable({}, match_star_star=true)", mime:...
rust_dataset_chunk_809
rust_dataset.txt
809
512
``` /// use actix_web::{web, guard::Host, HttpResponse}; /// /// web::scope("/admin") /// .guard(Host("admin.rust-lang.org").scheme("https")) /// .default_service(web::to(|| async { /// HttpResponse::Ok().body("admin connection is secure") /// })); /// ``` /// /// [virtual hosting]: https://en.wiki...
rust_dataset_chunk_810
rust_dataset.txt
810
512
fn name(&self) -> String { if let Some(ref scheme) = self.scheme { format!("Host({}, scheme={})", self.host, scheme) } else { format!("Host({})", self.host) } } #[cfg(feature = "experimental-introspection")] fn details(&self) -> Option<Vec<super::GuardDet...
rust_dataset_chunk_811
rust_dataset.txt
811
512
.org").scheme("https"); assert!(!host.check(&req.guard_ctx())); let host = Host("crates.io"); assert!(!host.check(&req.guard_ctx())); let host = Host("localhost"); assert!(!host.check(&req.guard_ctx())); } #[test] fn host_without_header() { let req = TestRe...
rust_dataset_chunk_812
rust_dataset.txt
812
512
assert!(details.iter().any(|detail| match detail { crate::guard::GuardDetail::Headers(headers) => headers .iter() .any(|(name, value)| name == "host" && value == "example.com"), _ => false, })); assert!(details.iter().any(|detail| match detail { ...
rust_dataset_chunk_813
rust_dataset.txt
813
512
an example of virtual hosting. //! //! # Examples //! //! In the following code, the `/guarded` resource has one defined route whose handler will only be //! called if the request method is GET or POST and there is a `x-guarded` request header with value //! equal to `secret`. //! //! ``` //! use actix_web::{web, http...
rust_dataset_chunk_814
rust_dataset.txt
814
512
/// Extracts a typed header from the request. /// /// Returns `None` if parsing `H` fails. /// /// # Examples /// ``` /// use actix_web::{guard::fn_guard, http::header}; /// /// let image_accept_guard = fn_guard(|ctx| { /// match ctx.header::<header::Accept>() { /// ...
rust_dataset_chunk_815
rust_dataset.txt
815
512
::Ok()); /// ``` pub fn fn_guard<F>(f: F) -> impl Guard where F: Fn(&GuardContext<'_>) -> bool, { FnGuard(f) } struct FnGuard<F: Fn(&GuardContext<'_>) -> bool>(F); impl<F> Guard for FnGuard<F> where F: Fn(&GuardContext<'_>) -> bool, { fn check(&self, ctx: &GuardContext<'_>) -> bool { (self.0)(...
rust_dataset_chunk_816
rust_dataset.txt
816
512
.map(|g| g.name()) .collect::<Vec<_>>() .join(", ") ) } #[cfg(feature = "experimental-introspection")] fn details(&self) -> Option<Vec<GuardDetail>> { Some( self.guards .iter() .flat_map(|g| g.details().unwrap_or_d...
rust_dataset_chunk_817
rust_dataset.txt
817
512
self.guards .iter() .flat_map(|g| g.details().unwrap_or_default()) .collect(), ) } } /// Wraps a guard and inverts the outcome of its `Guard` implementation. /// /// # Examples /// The handler below will be called for any request method apart from...
rust_dataset_chunk_818
rust_dataset.txt
818
512
{ #[doc = concat!("Creates a guard that matches the `", stringify!($method_const), "` request method.")] /// /// # Examples #[doc = concat!("The route in this example will only respond to `", stringify!($method_const), "` requests.")] /// ``` /// use actix_web::{guard, w...
rust_dataset_chunk_819
rust_dataset.txt
819
512
.get(&self.0) { return val == self.1; } false } #[cfg(feature = "experimental-introspection")] fn name(&self) -> String { format!("Header({}, {})", self.0, self.1.to_str().unwrap_or("")) } #[cfg(feature = "experimental-introspection")] fn details(&self) -> ...
rust_dataset_chunk_820
rust_dataset.txt
820
512
Head().check(&req.guard_ctx())); assert!(!Head().check(&get_req.guard_ctx())); let req = TestRequest::default() .method(Method::OPTIONS) .to_srv_request(); assert!(Options().check(&req.guard_ctx())); assert!(!Options().check(&get_req.guard_ctx())); let r...
rust_dataset_chunk_821
rust_dataset.txt
821
512
() { let domain = "rust-lang.org".to_owned(); let guard = fn_guard(|ctx| ctx.head().uri.host().unwrap().ends_with(&domain)); let req = TestRequest::default() .uri("blog.rust-lang.org") .to_srv_request(); assert!(guard.check(&req.guard_ctx())); let req = ...
rust_dataset_chunk_822
rust_dataset.txt
822
512
Compiler Errors /// /// If you get the error `the trait Handler<_> is not implemented`, then your handler does not /// fulfill the _first_ of the above requirements. (It could also mean that you're attempting to use /// a macro-routed handler in a manual routing context like `web::get().to(handler)`, which is not /// ...
rust_dataset_chunk_823
rust_dataset.txt
823
512
for Func /// where /// Func: Fn(Arg1, Arg2) -> Fut + Clone + 'static, /// Fut: Future, /// { /// type Output = Fut::Output; /// type Future = Fut; /// /// fn call(&self, (arg1, arg2): (Arg1, Arg2)) -> Self::Future { /// (self)(arg1, arg2) /// } /// } /// ``` /// /// [arity]: https://en....
rust_dataset_chunk_824
rust_dataset.txt
824
512
)) -> Self::Future { (self)($($param,)*) } } }); factory_tuple! {} factory_tuple! { A } factory_tuple! { A B } factory_tuple! { A B C } factory_tuple! { A B C D } factory_tuple! { A B C D E } factory_tuple! { A B C D E F } factory_tuple! { A B C D E F G } factory_tuple! { A B C D E F G H } fact...
rust_dataset_chunk_825
rust_dataset.txt
825
512
perform a remaining length check before writing. pub(crate) struct MutWriter<'a, B>(pub(crate) &'a mut B); impl<B> io::Write for MutWriter<'_, B> where B: BufMut, { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { self.0.put_slice(buf); Ok(buf.len()) } fn flush(&mut self) -> io:...
rust_dataset_chunk_826
rust_dataset.txt
826
512
q(0.9)), /// QualityItem::new(Charset::Iso_8859_10, q(0.2)), /// ])) /// .to_http_request(); /// # let _ = req; /// ``` /// /// ``` /// use actix_web::{http::header::{AcceptCharset, Charset, QualityItem}, test}; /// /// let req = test::TestRequest::default() ...
rust_dataset_chunk_827
rust_dataset.txt
827
512
, gzip` /// * `` /// * `*` /// * `compress;q=0.5, gzip;q=1` /// * `gzip;q=1.0, identity; q=0.5, *;q=0` /// /// # Examples /// ``` /// use actix_web::{http::header::{AcceptEncoding, Encoding, Preference, QualityItem}, test}; /// /// let req = test::TestRequest::default() /// ...
rust_dataset_chunk_828
rust_dataset.txt
828
512
cceptEncoding(vec![ QualityItem::max(Preference::Specific(Encoding::gzip())), QualityItem::zero(Preference::Any), ])) ); } } impl AcceptEncoding { /// Selects the most acceptable encoding according to client preference and supported types. /// /// The...
rust_dataset_chunk_829
rust_dataset.txt
829
512
.filter(|q| q.quality > Quality::ZERO) // search relies on item list being in descending order of quality .find(|q| { let enc = &q.item; matches!(enc, Preference::Specific(enc) if supported_set.contains(enc)) }) .map(|q| q.item); ...
rust_dataset_chunk_830
rust_dataset.txt
830
512
means all items had "q=0". match self.0.iter().find(|pref| { matches!( pref.item, Preference::Any | Preference::Specific(Encoding::Known(ContentEncoding::Identity)) ) }) { // "identit...
rust_dataset_chunk_831
rust_dataset.txt
831
512
1, Preference::Specific(Encoding::Unknown(_)) => 1, } } /// Returns true if "identity" is an acceptable encoding. /// /// Internal algorithm relies on item list being in descending order of quality. fn is_identity_acceptable(items: &'_ [QualityItem<Preference<Encoding>>]) -> bool { if items.is_empty()...
rust_dataset_chunk_832
rust_dataset.txt
832
512
"); assert!(is_identity_acceptable(&test)); let test = accept_encoding_ranked!("gzip", "identity;q=0.1", "*;q=0"); assert!(is_identity_acceptable(&test)); let test = accept_encoding_ranked!("gzip", "*;q=0", "identity;q=0.1"); assert!(is_identity_acceptable(&test)); let t...
rust_dataset_chunk_833
rust_dataset.txt
833
512
::gzip()), ); assert_eq!( test.negotiate([Encoding::brotli(), Encoding::identity()].iter()), None ); let test = accept_encoding!("gzip", "*;q=0"); assert_eq!( test.negotiate([Encoding::gzip(), Encoding::identity()].iter()), Some(En...
rust_dataset_chunk_834
rust_dataset.txt
834
512
().preference(), Some(Preference::Any)); assert_eq!(accept_encoding!("identity;q=0").preference(), None); assert_eq!(accept_encoding!("*;q=0").preference(), None); assert_eq!(accept_encoding!("compress;q=0", "*;q=0").preference(), None); assert_eq!(accept_encoding!("identity;q=0", "*;q=...
rust_dataset_chunk_835
rust_dataset.txt
835
512
/// ```plain /// Accept-Language = 1#( language-range [ weight ] ) /// language-range = (1*8ALPHA *("-" 1*8alphanum)) / "*" /// alphanum = ALPHA / DIGIT /// weight = OWS ";" OWS "q=" qvalue /// qvalue = ( "0" [ "." 0*3DIGIT ] ) /// / ( "1" [ "." 0*3(...
rust_dataset_chunk_836
rust_dataset.txt
836
512
7"] ); common_header_test!( not_ordered_by_weight, [b"en-US, en; q=0.5, fr"], Some(AcceptLanguage(vec![ QualityItem::max("en-US".parse().unwrap()), QualityItem::new("en".parse().unwrap(), q(0.5)), QualityItem::max("fr"...
rust_dataset_chunk_837
rust_dataset.txt
837
512
q-factor weighting]. /// /// [q-factor weighting]: https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2 pub fn ranked(&self) -> Vec<Preference<LanguageTag>> { if self.0.is_empty() { return vec![]; } let mut types = self.0.clone(); // use stable sort so it...
rust_dataset_chunk_838
rust_dataset.txt
838
512
parse().unwrap(), ] ); } #[test] fn preference_selection() { let test = AcceptLanguage(vec![ QualityItem::new("fr".parse().unwrap(), q(0.900)), QualityItem::new("fr-CH".parse().unwrap(), q(1.0)), QualityItem::new("en".parse().unwrap(), q(0.800...
rust_dataset_chunk_839
rust_dataset.txt
839
512
"*" ) /// / ( type "/" subtype ) /// ) *( OWS ";" OWS parameter ) /// accept-params = weight *( accept-ext ) /// accept-ext = OWS ";" OWS token [ "=" ( token / quoted-string ) ] /// ``` /// /// # Note /// This is a request header. Servers should not se...
rust_dataset_chunk_840
rust_dataset.txt
840
512
/// [RFC 7231 §5.3.2]: https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2 (Accept, header::ACCEPT) => (QualityItem<Mime>)* test_parse_and_format { // Tests from the RFC crate::http::header::common_header_test!( test1, [b"audio/*; q=0.2, audio/basic"], ...
rust_dataset_chunk_841
rust_dataset.txt
841
512
} /// Construct `Accept: text/*`. pub fn text() -> Accept { Accept(vec![QualityItem::max(mime::TEXT_STAR)]) } /// Construct `Accept: image/*`. pub fn image() -> Accept { Accept(vec![QualityItem::max(mime::IMAGE_STAR)]) } /// Construct `Accept: text/html`. pub fn html(...
rust_dataset_chunk_842
rust_dataset.txt
842
512
types.sort_by(|a, b| { // sort by q-factor descending b.quality.cmp(&a.quality).then_with(|| { // use specificity rules on mime types with // same q-factor (eg. text/html > text/* > */*) // subtypes are not comparable if main type is star...
rust_dataset_chunk_843
rust_dataset.txt
843
512
erves_quality_and_media_type() { let req = actix_http::test::TestRequest::default() .insert_header((header::ACCEPT, r#"text/plain; note="x; q=0.8""#)) .finish(); let accept = <Accept as header::Header>::parse(&req).unwrap(); assert_eq!(accept.len(), 1); assert_eq!...
rust_dataset_chunk_844
rust_dataset.txt
844
512
QualityItem::new(mime::STAR_STAR, q(0.5)), QualityItem::max(mime::IMAGE_SVG), QualityItem::new(mime::IMAGE_STAR, q(0.8)), ]); assert_eq!(test.preference(), mime::IMAGE_PNG); } } --- FILE: actix-web/actix-web/src/http/header/allow.rs --- use actix_http::Method; use crate::...
rust_dataset_chunk_845
rust_dataset.txt
845
512
!( test2, [b"OPTIONS, GET, PUT, POST, DELETE, HEAD, TRACE, CONNECT, PATCH"], Some(HeaderField(vec![ Method::OPTIONS, Method::GET, Method::PUT, Method::POST, Method::DELETE, Method::HEAD, ...
rust_dataset_chunk_846
rust_dataset.txt
846
512
Display> fmt::Display for AnyOrSome<T> { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { AnyOrSome::Any => f.write_char('*'), AnyOrSome::Item(item) => fmt::Display::fmt(item, f), } } } impl<T: str::FromStr> str::FromStr for AnyOrSome...
rust_dataset_chunk_847
rust_dataset.txt
847
512
(vec![ /// CacheDirective::NoCache, /// CacheDirective::Private, /// CacheDirective::MaxAge(360u32), /// CacheDirective::Extension("foo".to_owned(), Some("bar".to_owned())), /// ])); /// ``` (CacheControl, header::CACHE_CONTROL) => (CacheDirective)+ test_parse_and_format...
rust_dataset_chunk_848
rust_dataset.txt
848
512
/// "private" Private, /// "proxy-revalidate" ProxyRevalidate, /// "s-maxage=delta" SMaxAge(u32), /// Extension directives. Optionally include an argument. Extension(String, Option<String>), } impl fmt::Display for CacheDirective { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::...
rust_dataset_chunk_849
rust_dataset.txt
849
512
secs.parse().map(MaxStale).map_err(Some), ("min-fresh", secs) => secs.parse().map(MinFresh).map_err(Some), ("s-maxage", secs) => secs.parse().map(SMaxAge).map_err(Some), (left, right) => Ok(Extension(left.to_owned(), Some(right.to_owned()))), ...
rust_dataset_chunk_850
rust_dataset.txt
850
512
_end(), last.trim_start()) } /// The implied disposition of the content of the HTTP body. #[derive(Debug, Clone, PartialEq, Eq)] pub enum DispositionType { /// Inline implies default processing. Inline, /// Attachment implies that the recipient should prompt the user to save the response locally, /// ...
rust_dataset_chunk_851
rust_dataset.txt
851
512
.2](https://datatracker.ietf.org/doc/html/rfc7578#section-4.2). FilenameExt(ExtendedValue), /// An unrecognized regular parameter as defined in /// [RFC 5987 §3.2.1](https://datatracker.ietf.org/doc/html/rfc5987#section-3.2.1) as /// `reg-parameter`, in /// [RFC 6266 §4.1](https://datatracker.ietf....
rust_dataset_chunk_852
rust_dataset.txt
852
512
_ext<T: AsRef<str>>(&self, name: T) -> bool { self.as_unknown_ext(name).is_some() } /// Returns the name if applicable. #[inline] pub fn as_name(&self) -> Option<&str> { match self { DispositionParam::Name(name) => Some(name.as_str()), _ => None, } } ...
rust_dataset_chunk_853
rust_dataset.txt
853
512
inline* in the browser, that is, as a Web page or as /// part of a Web page, or as an attachment, that is downloaded and saved locally, and also can be /// used to attach additional metadata, such as the filename to use when saving the response payload /// locally. /// /// In a *multipart/form-data* body, the HTTP *Con...
rust_dataset_chunk_854
rust_dataset.txt
854
512
parameters: vec![DispositionParam::FilenameExt(ExtendedValue { /// charset: Charset::Iso_8859_1, // The character set for the bytes of the filename /// language_tag: None, // The optional language tag (see `language-tag` crate) /// value: b"\xA9 Ferris 2011.txt".to_vec(), // the actual byte...
rust_dataset_chunk_855
rust_dataset.txt
855
512
/docs/Web/HTTP/Headers/Content-Disposition#as_a_header_for_a_multipart_body /// [RFC 7587]: https://datatracker.ietf.org/doc/html/rfc7578 #[derive(Debug, Clone, PartialEq, Eq)] pub struct ContentDisposition { /// The disposition type pub disposition: DispositionType, /// Disposition parameters pub para...
rust_dataset_chunk_856
rust_dataset.txt
856
512
.into(), parameters: Vec::new(), }; while !left.is_empty() { let (param_name, new_left) = split_once_and_trim(left, '='); if param_name.is_empty() || param_name == "*" || new_left.is_empty() { return Err(crate::error::ParseError::Header); ...
rust_dataset_chunk_857
rust_dataset.txt
857
512
cannot be empty return Err(crate::error::ParseError::Header); } token.to_owned() }; let param = if param_name.eq_ignore_ascii_case("name") { DispositionParam::Name(value) } else if param...
rust_dataset_chunk_858
rust_dataset.txt
858
512
self.parameters.iter().find_map(|p| p.as_unknown(name)) } /// Return the value of the extended parameter which the `name` matches. pub fn get_unknown_ext(&self, name: impl AsRef<str>) -> Option<&ExtendedValue> { let name = name.as_ref(); self.parameters.iter().find_map(|p| p.as_unkn...
rust_dataset_chunk_859
rust_dataset.txt
859
512
"\" CHAR // TEXT = <any OCTET except CTLs, // but including LWS> // LWS = [CRLF] 1*( SP | HT ) // OCTET = <any 8-bit sequence of data> // CHAR = <any US-ASCII character (octets 0 - 127)> // CTL = <any US...
rust_dataset_chunk_860
rust_dataset.txt
860
512
_>) -> fmt::Result { write!(f, "{}", self.disposition)?; self.parameters .iter() .try_for_each(|param| write!(f, "; {}", param)) } } #[cfg(test)] mod tests { use super::{ContentDisposition, DispositionParam, DispositionType}; use crate::http::header::{Charset, Extend...
rust_dataset_chunk_861
rust_dataset.txt
861
512
_eq!(a, b); let a = HeaderValue::from_static( "attachment; creation-date=\"Wed, 12 Feb 1997 16:29:51 -0500\"", ); let a: ContentDisposition = ContentDisposition::from_raw(&a).unwrap(); let b = ContentDisposition { disposition: DispositionType::Attachment, ...
rust_dataset_chunk_862
rust_dataset.txt
862
512
b't', b'e', b's', ], })], }; assert_eq!(a, b); } #[test] fn test_from_raw_extra_whitespace() { let a = HeaderValue::from_static( "form-data ; du-mmy= 3 ; name =upload ; filename = \"sample.png\" ; ", ); let a: ContentDispo...
rust_dataset_chunk_863
rust_dataset.txt
863
512
_static("attachment")).unwrap(); let b = ContentDisposition { disposition: DispositionType::Attachment, parameters: vec![], }; assert_eq!(a, b); let a = ContentDisposition::from_raw(&HeaderValue::from_static("inline ;")).unwrap(); let b = ContentDispositi...
rust_dataset_chunk_864
rust_dataset.txt
864
512
Param::Name(String::from("upload")), DispositionParam::Filename(String::from("文件.webp")), ], }; assert_eq!(a, b); let a = HeaderValue::from_str( "form-data; name=upload; filename=\"余固知謇謇之為患兮,忍而不能舍也.pptx\"", ) .unwrap(); let a: Cont...
rust_dataset_chunk_865
rust_dataset.txt
865
512
2 and 4.2 suggests that filename with // non-ASCII characters MAY be percent-encoded. // On the contrary, RFC 6266 or other RFCs related to Content-Disposition response header // do not mention such percent-encoding. // So, it appears to be undecidable whether to percent-decode or not wi...
rust_dataset_chunk_866
rust_dataset.txt
866
512
from_raw(&a).is_err()); let a = HeaderValue::from_static("inline; filename=\"\""); assert!(ContentDisposition::from_raw(&a) .expect("Parse cd") .get_filename() .expect("Filename") .is_empty()); } #[test] fn test_from_raw_param_name_missing() ...
rust_dataset_chunk_867
rust_dataset.txt
867
512
display_rendered = format!("{}", a); assert_eq!(as_string, display_rendered); let a: ContentDisposition = ContentDisposition { disposition: DispositionType::Inline, parameters: vec![DispositionParam::Filename(String::from("Tab\there.png"))], }; let display_rende...
rust_dataset_chunk_868
rust_dataset.txt
868
512
FILE: actix-web/actix-web/src/http/header/content_language.rs --- use language_tags::LanguageTag; use super::{common_header, QualityItem, CONTENT_LANGUAGE}; common_header! { /// `Content-Language` header, defined /// in [RFC 7231 §3.1.3.2](https://datatracker.ietf.org/doc/html/rfc7231#section-3.1.3.2) //...
rust_dataset_chunk_869
rust_dataset.txt
869
512
, HeaderValue, TryIntoHeaderValue, CONTENT_LENGTH, }, HttpMessage, }; /// `Content-Length` header, defined in [RFC 9110 §8.6]. /// /// The Content-Length /// /// # ABNF /// /// ```plain /// Content-Length = 1*DIGIT /// ``` /// /// # Example Values /// /// - `0` /// - `3495` /// /// # Examples /// /// ``` /// u...
rust_dataset_chunk_870
rust_dataset.txt
870
512
impl PartialEq<usize> for ContentLength { fn eq(&self, other: &usize) -> bool { self.0 == *other } } impl PartialEq<ContentLength> for usize { fn eq(&self, other: &ContentLength) -> bool { *self == other.0 } } impl PartialOrd<usize> for ContentLength { fn partial_cmp(&self, other: ...
rust_dataset_chunk_871
rust_dataset.txt
871
512
assert_parse_fail::<ContentLength, _, _>(["123_456"]); assert_parse_fail::<ContentLength, _, _>(["123.456"]); // too large for u64 (2^64, 2^64 + 1) assert_parse_fail::<ContentLength, _, _>(["18446744073709551616"]); assert_parse_fail::<ContentLength, _, _>(["18446744073709551617"]); ...
rust_dataset_chunk_872
rust_dataset.txt
872
512
123)); } #[test] fn ordering() { assert!(ContentLength(0) < ContentLength(123)); assert!(ContentLength(0) < 123); assert!(0 < ContentLength(123)); } } --- FILE: actix-web/actix-web/src/http/header/content_range.rs --- use std::{ fmt::{self, Display, Write}, str::FromSt...
rust_dataset_chunk_873
rust_dataset.txt
873
512
, [b""], None::<ContentRange>); crate::http::header::common_header_test!(test_bytes_many_spaces, [b"bytes 1-2/500 3"], None::<ContentRange>); crate::http::header::common_header_test!(test_bytes_many_slashes, [b"bytes 1-2/500/600"], ...
rust_dataset_chunk_874
rust_dataset.txt
874
512
Some(instance_length.parse().map_err(|_| ParseError::Header)?) }; let range = if range == "*" { None } else { let (first_byte, last_byte) = range.split_once('-').ok_or(ParseError::Header)?; ...
rust_dataset_chunk_875
rust_dataset.txt
875
512
` header field indicates the media type of the associated representation: /// either the representation enclosed in the message payload or the selected representation, /// as determined by the message semantics. The indicated media type defines both the data /// format and how that data is intended to be pr...
rust_dataset_chunk_876
rust_dataset.txt
876
512
. #[inline] pub fn html() -> ContentType { ContentType(mime::TEXT_HTML_UTF_8) } /// Constructs a `Content-Type: text/xml` header. #[inline] pub fn xml() -> ContentType { ContentType(mime::TEXT_XML) } /// Constructs a `Content-Type: application/www-form-url-encoded` head...
rust_dataset_chunk_877
rust_dataset.txt
877
512
08:12:31 GMT"]); } } impl Date { /// Create a date instance set to the current system time pub fn now() -> Date { Date(SystemTime::now().into()) } } --- FILE: actix-web/actix-web/src/http/header/encoding.rs --- use std::{fmt, str}; use actix_http::ContentEncoding; /// A value to represent ...
rust_dataset_chunk_878
rust_dataset.txt
878
512
8) -> bool { c == 0x21 || (0x23..=0x7e).contains(&c) || (c >= 0x80) } fn check_slice_validity(slice: &str) -> bool { slice.bytes().all(entity_validate_char) } /// An entity tag, defined in [RFC 7232 §2.3]. /// /// An entity tag consists of a string enclosed by two literal double quotes. /// Preceding the firs...
rust_dataset_chunk_879
rust_dataset.txt
879
512
/// /// # Panics /// If the tag contains invalid characters. pub fn new(weak: bool, tag: String) -> EntityTag { assert!(check_slice_validity(&tag), "Invalid tag: {:?}", tag); EntityTag { weak, tag } } /// Constructs a new weak EntityTag. /// /// # Panics /// If the t...
rust_dataset_chunk_880
rust_dataset.txt
880
512
of `weak_eq()`. pub fn weak_ne(&self, other: &EntityTag) -> bool { !self.weak_eq(other) } } impl Display for EntityTag { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if self.weak { write!(f, "W/\"{}\"", self.tag) } else { write!(f, "\"{}\"", se...
rust_dataset_chunk_881
rust_dataset.txt
881
512
"\"\"".parse::<EntityTag>().unwrap(), EntityTag::new_strong("".to_owned()) ); assert_eq!( "W/\"weaktag\"".parse::<EntityTag>().unwrap(), EntityTag::new_weak("weaktag".to_owned()) ); assert_eq!( "W/\"\x65\x62\"".parse::<EntityTag...
rust_dataset_chunk_882
rust_dataset.txt
882
512
| // | `"1"` | `"1"` | match | match | let mut etag1 = EntityTag::new_weak("1".to_owned()); let mut etag2 = EntityTag::new_weak("1".to_owned()); assert!(!etag1.strong_eq(&etag2)); assert!(etag1.weak_eq(&etag2)); assert!(etag1.strong_ne...
rust_dataset_chunk_883
rust_dataset.txt
883
512
/// due to resource state changes over time, content negotiation /// resulting in multiple representations being valid at the same time, /// or both. An entity-tag consists of an opaque quoted string, possibly /// prefixed by a weakness indicator. /// /// # ABNF /// ```plain /// ETag ...
rust_dataset_chunk_884
rust_dataset.txt
884
512
Some(ETag(EntityTag::new_weak("weak-etag".to_owned())))); crate::http::header::common_header_test!(test7, [b"W/\"\x65\x62\""], Some(ETag(EntityTag::new_weak("\u{0065}\u{0062}".to_owned())))); crate::http::header::common_header_test!(test8, [b"W/\"\""], So...
rust_dataset_chunk_885
rust_dataset.txt
885
512
/// # Examples /// /// ``` /// use std::time::{SystemTime, Duration}; /// use actix_web::HttpResponse; /// use actix_web::http::header::Expires; /// /// let mut builder = HttpResponse::Ok(); /// let expiration = SystemTime::now() + Duration::from_secs(60 * 60 * 24); /// builder.inse...
rust_dataset_chunk_886
rust_dataset.txt
886
512
``` /// use actix_web::{http::header::IfMatch, test}; /// /// let req = test::TestRequest::default() /// .insert_header(IfMatch::Any) /// .to_http_request(); /// # let _ = req; /// ``` /// /// ``` /// use actix_web::{http::header::{EntityTag, IfMatch}, test}; /// ...
rust_dataset_chunk_887
rust_dataset.txt
887
512
3](https://datatracker.ietf.org/doc/html/rfc7232#section-3.3) /// /// The `If-Modified-Since` header field makes a GET or HEAD request /// method conditional on the selected representation's modification date /// being more recent than the date provided in the field-value. /// Transfer of the select...
rust_dataset_chunk_888
rust_dataset.txt
888
512
-value is "*", /// or having a selected representation with an entity-tag that does not /// match any of those listed in the field-value. /// /// A recipient MUST use the weak comparison function when comparing /// entity-tags for If-None-Match (Section 2.3.2), since weak entity-tags /// can be ...
rust_dataset_chunk_889
rust_dataset.txt
889
512
common_header_test!(test2, [b"W/\"xyzzy\""]); crate::http::header::common_header_test!(test3, [b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""]); crate::http::header::common_header_test!(test4, [b"W/\"xyzzy\", W/\"r2d2xxxx\", W/\"c3piozzzz\""]); crate::http::header::common_header_test!(test5, [b"*"]);...
rust_dataset_chunk_890
rust_dataset.txt
890
512
use the /// Range header field with a conditional GET (using either or both of /// If-Unmodified-Since and If-Match.) However, if the precondition /// fails because the representation has been modified, the client would /// then have to make a second request to obtain the entire current /// representation. /// /// Th...
rust_dataset_chunk_891
rust_dataset.txt
891
512
)); if let Ok(etag) = etag { return Ok(IfRange::EntityTag(etag)); } let date: Result<HttpDate, _> = from_one_raw_str(msg.headers().get(&header::IF_RANGE)); if let Ok(date) = date { return Ok(IfRange::Date(date)); } Err(ParseError::Header) } } ...
rust_dataset_chunk_892
rust_dataset.txt
892
512
/// This is a request header used for conditional requests. Servers should not send /// `If-Unmodified-Since` in responses; use [`LastModified`](super::LastModified) / the /// `Last-Modified` header instead. /// /// # ABNF /// ```plain /// If-Unmodified-Since = HTTP-date /// ``` /// ...
rust_dataset_chunk_893
rust_dataset.txt
893
512
/// use actix_web::http::header::LastModified; /// /// let mut builder = HttpResponse::Ok(); /// let modified = SystemTime::now() - Duration::from_secs(60 * 60 * 24); /// builder.insert_header( /// LastModified(modified.into()) /// ); /// ``` (LastModified, LAST_MODIFIED) => [Htt...
rust_dataset_chunk_894
rust_dataset.txt
894
512
#[test] fn $id() { use actix_http::test; let headers = $raw.iter().map(|x| x.to_vec()).collect::<Vec<_>>(); let mut req = test::TestRequest::default(); for item in headers { req.append_header((HeaderField::name(), item)); } ...
rust_dataset_chunk_895
rust_dataset.txt
895
512
#[inline] fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { $crate::http::header::fmt_comma_delimited(f, &self.0[..]) } } impl $crate::http::header::TryIntoHeaderValue for $id { type Error = $crate::http::header::InvalidHeade...
rust_dataset_chunk_896
rust_dataset.txt
896
512
http::header::HeaderValue, Self::Error> { use ::core::fmt::Write; let mut writer = $crate::http::header::Writer::new(); let _ = write!(&mut writer, "{}", self); $crate::http::header::HeaderValue::from_maybe_shared(writer.take()) } } ...
rust_dataset_chunk_897
rust_dataset.txt
897
512
HeaderName { $name } #[inline] fn parse<M: $crate::HttpMessage>(msg: &M) -> Result<Self, $crate::error::ParseError> { let is_any = msg .headers() .get(Self::name()) .and_then(|hdr| hdr.to_str...
rust_dataset_chunk_898
rust_dataset.txt
898
512
, $n) => ($item)+ } crate::http::header::common_header_test_module! { $id, $tm { $($tf)* }} }; ($(#[$attrs:meta])*($id:ident, $name:expr) => [$item:ty] $tm:ident{$($tf:item)*}) => { crate::http::header::common_header! { $(#[$attrs])* ($id, $name) => [$item] } ...
rust_dataset_chunk_899
rust_dataset.txt
899
512
_test; pub(crate) use self::macros::{common_header, common_header_test_module}; pub use self::{ accept::Accept, accept_charset::AcceptCharset, accept_encoding::AcceptEncoding, accept_language::AcceptLanguage, allow::Allow, cache_control::{CacheControl, CacheDirective}, content_disposition::{...