Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioBenitez committed Jan 16, 2024
1 parent d302edb commit e71a2ed
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 51 deletions.
7 changes: 3 additions & 4 deletions contrib/ws/src/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,9 @@ impl<'r> FromRequest<'r> for WebSocket {
let is_13 = headers.get_one("Sec-WebSocket-Version").map_or(false, |v| v == "13");
let key = headers.get_one("Sec-WebSocket-Key").map(|k| derive_accept_key(k.as_bytes()));
match key {
Some(key) if is_upgrade && is_ws && is_13 => Outcome::Success(WebSocket {
key,
config: Config::default(),
}),
Some(key) if is_upgrade && is_ws && is_13 => {
Outcome::Success(WebSocket { key, config: Config::default() })
},
Some(_) | None => Outcome::Forward(Status::BadRequest)
}
}
Expand Down
15 changes: 8 additions & 7 deletions core/codegen/src/attribute/async_bound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use syn::{TraitItemFn, TypeParamBound, ReturnType, Attribute};
use syn::punctuated::Punctuated;
use syn::parse::Parser;

// TODO: Try to make rust-analyzer generate the right scaffold for impls.
fn _async_bound(
args: proc_macro::TokenStream,
input: proc_macro::TokenStream
Expand All @@ -16,7 +15,7 @@ fn _async_bound(
}

let mut func: TraitItemFn = syn::parse(input)?;
let mut original: TraitItemFn = func.clone();
let original: TraitItemFn = func.clone();
if !func.sig.asyncness.is_some() {
let diag = Span::call_site()
.error("attribute can only be applied to async fns")
Expand All @@ -34,20 +33,22 @@ fn _async_bound(
};

func.sig.asyncness = None;
func.attrs.push(doc.clone());
func.sig.output = match func.sig.output {
ReturnType::Type(arrow, ty) => parse_quote_spanned!(ty.span() =>
#arrow impl ::core::future::Future<Output = #ty> + #bounds
),
default@ReturnType::Default => default
};

original.attrs.push(doc);
Ok(quote!{
#[cfg(all(nightly, doc))]
Ok(quote! {
#[cfg(all(not(doc), rust_analyzer))]
#original

#[cfg(not(all(nightly, doc)))]
#[cfg(all(doc, not(rust_analyzer)))]
#doc
#original

#[cfg(not(any(doc, rust_analyzer)))]
#func
})
}
Expand Down
1 change: 0 additions & 1 deletion core/http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ smallvec = { version = "1.11", features = ["const_generics", "const_new"] }
percent-encoding = "2"
time = { version = "0.3", features = ["formatting", "macros"] }
indexmap = "2"
tokio = { version = "1.6.1", features = ["net", "sync", "time"] }
ref-cast = "1.0"
uncased = "0.9.6"
either = "1"
Expand Down
24 changes: 12 additions & 12 deletions core/http/src/header/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,18 @@ impl<'h> HeaderMap<'h> {
}
}

impl From<cookie::Cookie<'_>> for Header<'static> {
fn from(cookie: cookie::Cookie<'_>) -> Header<'static> {
Header::new("Set-Cookie", cookie.encoded().to_string())
}
}

impl From<&cookie::Cookie<'_>> for Header<'static> {
fn from(cookie: &cookie::Cookie<'_>) -> Header<'static> {
Header::new("Set-Cookie", cookie.encoded().to_string())
}
}

#[cfg(test)]
mod tests {
use super::HeaderMap;
Expand Down Expand Up @@ -777,15 +789,3 @@ mod tests {
assert_eq!(vals, vec!["a", "b", "c"]);
}
}

impl From<cookie::Cookie<'_>> for Header<'static> {
fn from(cookie: cookie::Cookie<'_>) -> Header<'static> {
Header::new("Set-Cookie", cookie.encoded().to_string())
}
}

impl From<&cookie::Cookie<'_>> for Header<'static> {
fn from(cookie: &cookie::Cookie<'_>) -> Header<'static> {
Header::new("Set-Cookie", cookie.encoded().to_string())
}
}
5 changes: 2 additions & 3 deletions core/lib/src/data/data_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ use std::path::Path;
use std::io::{self, Cursor};

use futures::ready;
use futures::stream::Stream;
use tokio::fs::File;
use tokio::io::{AsyncRead, AsyncWrite, AsyncReadExt, ReadBuf, Take};
use tokio_util::io::StreamReader;
use hyper::body::{Body, Incoming as HyperBody};
use futures::stream::Stream;
use hyper::body::{Body, Bytes, Incoming as HyperBody};

use crate::data::{Capped, N};
use crate::http::hyper::body::Bytes;
use crate::data::transform::Transform;
use crate::util::Chain;

Expand Down
5 changes: 2 additions & 3 deletions core/lib/src/data/io_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use std::io;
use std::task::{Context, Poll};
use std::pin::Pin;

use hyper_util::rt::TokioIo;
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};

use crate::http::hyper::upgrade::Upgraded;
use hyper::upgrade::Upgraded;
use hyper_util::rt::TokioIo;

/// A bidirectional, raw stream to the client.
///
Expand Down
2 changes: 1 addition & 1 deletion core/lib/src/http/cookies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ impl<'a> CookieJar<'a> {
cookie.set_expires(time::OffsetDateTime::now_utc() + time::Duration::weeks(1));
}

// FIMME: Check security.
// FIXME: Check if TLS is enabled.
if cookie.secure().is_none() /* && config.tls_enabled() */ {
cookie.set_secure(true);
}
Expand Down
12 changes: 0 additions & 12 deletions core/lib/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,5 @@ mod cookies;
#[doc(inline)]
pub use rocket_http::*;

/// Re-exported hyper HTTP library types.
///
/// All types that are re-exported from Hyper reside inside of this module.
/// These types will, with certainty, be removed with time, but they reside here
/// while necessary.
pub mod hyper {
#[doc(hidden)]
pub use hyper::*;

pub use hyper::header;
}

#[doc(inline)]
pub use cookies::*;
7 changes: 3 additions & 4 deletions core/lib/src/listener/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ mod socketaddr;
mod connection;
mod bindable;

pub mod default;

pub mod tcp;

#[cfg(unix)]
#[cfg_attr(nightly, doc(cfg(unix)))]
pub mod uds;
Expand All @@ -17,6 +13,9 @@ pub mod uds;
#[cfg_attr(nightly, doc(cfg(feature = "tls")))]
pub mod tls;

pub mod default;
pub mod tcp;

pub use socketaddr::*;
pub use listener::*;
pub use connection::*;
Expand Down
5 changes: 2 additions & 3 deletions core/lib/src/request/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ use crate::request::{FromParam, FromSegments, FromRequest, Outcome, AtomicMethod
use crate::form::{self, ValueField, FromForm};
use crate::data::Limits;

use crate::http::{hyper, Method, Header, HeaderMap};
use crate::http::{ContentType, Accept, MediaType, CookieJar, Cookie};
use crate::http::uncased::UncasedStr;
use crate::http::{Method, Header, HeaderMap, ContentType, Accept, MediaType, CookieJar, Cookie};
use crate::http::uri::{fmt::Path, Origin, Segments, Host, Authority};
use crate::http::uncased::UncasedStr;
use crate::listener::{Certificates, SocketAddr, Connection};

/// The type of an incoming web request.
Expand Down
1 change: 0 additions & 1 deletion core/lib/src/request/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::collections::HashMap;

use crate::request::{Request, ConnectionMeta};
use crate::local::blocking::Client;
use crate::http::hyper;

macro_rules! assert_headers {
($($key:expr => [$($value:expr),+]),+) => ({
Expand Down

0 comments on commit e71a2ed

Please sign in to comment.