mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-25 06:39:22 +02:00
fork cookie crate
This commit is contained in:
@ -18,17 +18,14 @@ name = "awc"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = ["ssl", "brotli", "flate2-zlib", "cookies"]
|
||||
features = ["ssl", "brotli", "flate2-zlib"]
|
||||
|
||||
[features]
|
||||
default = ["cookies", "brotli", "flate2-zlib"]
|
||||
default = ["brotli", "flate2-zlib"]
|
||||
|
||||
# openssl
|
||||
ssl = ["openssl", "actix-http/ssl"]
|
||||
|
||||
# cookies integration
|
||||
cookies = ["cookie", "actix-http/cookies"]
|
||||
|
||||
# brotli encoding, requires c compiler
|
||||
brotli = ["actix-http/brotli"]
|
||||
|
||||
@ -53,8 +50,6 @@ serde = "1.0"
|
||||
serde_json = "1.0"
|
||||
serde_urlencoded = "0.5.3"
|
||||
tokio-timer = "0.2.8"
|
||||
|
||||
cookie = { version="0.11", features=["percent-encode"], optional = true }
|
||||
openssl = { version="0.10", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -24,7 +24,7 @@ use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::time::Duration;
|
||||
|
||||
pub use actix_http::{client::Connector, http};
|
||||
pub use actix_http::{client::Connector, cookie, http};
|
||||
|
||||
use actix_http::http::{HeaderMap, HttpTryFrom, Method, Uri};
|
||||
use actix_http::RequestHead;
|
||||
|
@ -1,18 +1,19 @@
|
||||
use std::fmt;
|
||||
use std::fmt::Write as FmtWrite;
|
||||
use std::io::Write;
|
||||
use std::rc::Rc;
|
||||
use std::time::Duration;
|
||||
|
||||
use bytes::{BufMut, Bytes, BytesMut};
|
||||
#[cfg(feature = "cookies")]
|
||||
use cookie::{Cookie, CookieJar};
|
||||
use futures::future::{err, Either};
|
||||
use futures::{Future, Stream};
|
||||
use percent_encoding::{percent_encode, USERINFO_ENCODE_SET};
|
||||
use serde::Serialize;
|
||||
use serde_json;
|
||||
use tokio_timer::Timeout;
|
||||
|
||||
use actix_http::body::{Body, BodyStream};
|
||||
use actix_http::cookie::{Cookie, CookieJar};
|
||||
use actix_http::encoding::Decoder;
|
||||
use actix_http::http::header::{self, ContentEncoding, Header, IntoHeaderValue};
|
||||
use actix_http::http::{
|
||||
@ -59,7 +60,6 @@ const HTTPS_ENCODING: &str = "gzip, deflate";
|
||||
pub struct ClientRequest {
|
||||
pub(crate) head: RequestHead,
|
||||
err: Option<HttpError>,
|
||||
#[cfg(feature = "cookies")]
|
||||
cookies: Option<CookieJar>,
|
||||
default_headers: bool,
|
||||
response_decompress: bool,
|
||||
@ -77,7 +77,6 @@ impl ClientRequest {
|
||||
config,
|
||||
head: RequestHead::default(),
|
||||
err: None,
|
||||
#[cfg(feature = "cookies")]
|
||||
cookies: None,
|
||||
timeout: None,
|
||||
default_headers: true,
|
||||
@ -268,7 +267,6 @@ impl ClientRequest {
|
||||
self.header(header::AUTHORIZATION, format!("Bearer {}", token))
|
||||
}
|
||||
|
||||
#[cfg(feature = "cookies")]
|
||||
/// Set a cookie
|
||||
///
|
||||
/// ```rust
|
||||
@ -437,28 +435,20 @@ impl ClientRequest {
|
||||
}
|
||||
};
|
||||
|
||||
#[allow(unused_mut)]
|
||||
let mut head = slf.head;
|
||||
|
||||
#[cfg(feature = "cookies")]
|
||||
{
|
||||
use percent_encoding::{percent_encode, USERINFO_ENCODE_SET};
|
||||
use std::fmt::Write;
|
||||
|
||||
// set cookies
|
||||
if let Some(ref mut jar) = slf.cookies {
|
||||
let mut cookie = String::new();
|
||||
for c in jar.delta() {
|
||||
let name = percent_encode(c.name().as_bytes(), USERINFO_ENCODE_SET);
|
||||
let value =
|
||||
percent_encode(c.value().as_bytes(), USERINFO_ENCODE_SET);
|
||||
let _ = write!(&mut cookie, "; {}={}", name, value);
|
||||
}
|
||||
head.headers.insert(
|
||||
header::COOKIE,
|
||||
HeaderValue::from_str(&cookie.as_str()[2..]).unwrap(),
|
||||
);
|
||||
// set cookies
|
||||
if let Some(ref mut jar) = slf.cookies {
|
||||
let mut cookie = String::new();
|
||||
for c in jar.delta() {
|
||||
let name = percent_encode(c.name().as_bytes(), USERINFO_ENCODE_SET);
|
||||
let value = percent_encode(c.value().as_bytes(), USERINFO_ENCODE_SET);
|
||||
let _ = write!(&mut cookie, "; {}={}", name, value);
|
||||
}
|
||||
head.headers.insert(
|
||||
header::COOKIE,
|
||||
HeaderValue::from_str(&cookie.as_str()[2..]).unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
let config = slf.config;
|
||||
|
@ -9,10 +9,8 @@ use actix_http::http::header::{CONTENT_LENGTH, SET_COOKIE};
|
||||
use actix_http::http::{HeaderMap, StatusCode, Version};
|
||||
use actix_http::{Extensions, HttpMessage, Payload, PayloadStream, ResponseHead};
|
||||
|
||||
#[cfg(feature = "cookies")]
|
||||
use actix_http::cookie::Cookie;
|
||||
use actix_http::error::CookieParseError;
|
||||
#[cfg(feature = "cookies")]
|
||||
use cookie::Cookie;
|
||||
|
||||
/// Client Response
|
||||
pub struct ClientResponse<S = PayloadStream> {
|
||||
@ -41,7 +39,6 @@ impl<S> HttpMessage for ClientResponse<S> {
|
||||
|
||||
/// Load request cookies.
|
||||
#[inline]
|
||||
#[cfg(feature = "cookies")]
|
||||
fn cookies(&self) -> Result<Ref<Vec<Cookie<'static>>>, CookieParseError> {
|
||||
struct Cookies(Vec<Cookie<'static>>);
|
||||
|
||||
|
@ -1,10 +1,12 @@
|
||||
//! Test helpers for actix http client to use during testing.
|
||||
use actix_http::http::header::{Header, IntoHeaderValue};
|
||||
use std::fmt::Write as FmtWrite;
|
||||
|
||||
use actix_http::cookie::{Cookie, CookieJar};
|
||||
use actix_http::http::header::{self, Header, HeaderValue, IntoHeaderValue};
|
||||
use actix_http::http::{HeaderName, HttpTryFrom, Version};
|
||||
use actix_http::{h1, Payload, ResponseHead};
|
||||
use bytes::Bytes;
|
||||
#[cfg(feature = "cookies")]
|
||||
use cookie::{Cookie, CookieJar};
|
||||
use percent_encoding::{percent_encode, USERINFO_ENCODE_SET};
|
||||
|
||||
use crate::ClientResponse;
|
||||
|
||||
@ -30,7 +32,6 @@ where
|
||||
/// Test `ClientResponse` builder
|
||||
pub struct TestResponse {
|
||||
head: ResponseHead,
|
||||
#[cfg(feature = "cookies")]
|
||||
cookies: CookieJar,
|
||||
payload: Option<Payload>,
|
||||
}
|
||||
@ -39,7 +40,6 @@ impl Default for TestResponse {
|
||||
fn default() -> TestResponse {
|
||||
TestResponse {
|
||||
head: ResponseHead::default(),
|
||||
#[cfg(feature = "cookies")]
|
||||
cookies: CookieJar::new(),
|
||||
payload: None,
|
||||
}
|
||||
@ -87,7 +87,6 @@ impl TestResponse {
|
||||
}
|
||||
|
||||
/// Set cookie for this response
|
||||
#[cfg(feature = "cookies")]
|
||||
pub fn cookie<'a>(mut self, cookie: Cookie<'a>) -> Self {
|
||||
self.cookies.add(cookie.into_owned());
|
||||
self
|
||||
@ -105,25 +104,17 @@ impl TestResponse {
|
||||
pub fn finish(self) -> ClientResponse {
|
||||
let mut head = self.head;
|
||||
|
||||
#[cfg(feature = "cookies")]
|
||||
{
|
||||
use std::fmt::Write as FmtWrite;
|
||||
|
||||
use actix_http::http::header::{self, HeaderValue};
|
||||
use percent_encoding::{percent_encode, USERINFO_ENCODE_SET};
|
||||
|
||||
let mut cookie = String::new();
|
||||
for c in self.cookies.delta() {
|
||||
let name = percent_encode(c.name().as_bytes(), USERINFO_ENCODE_SET);
|
||||
let value = percent_encode(c.value().as_bytes(), USERINFO_ENCODE_SET);
|
||||
let _ = write!(&mut cookie, "; {}={}", name, value);
|
||||
}
|
||||
if !cookie.is_empty() {
|
||||
head.headers.insert(
|
||||
header::SET_COOKIE,
|
||||
HeaderValue::from_str(&cookie.as_str()[2..]).unwrap(),
|
||||
);
|
||||
}
|
||||
let mut cookie = String::new();
|
||||
for c in self.cookies.delta() {
|
||||
let name = percent_encode(c.name().as_bytes(), USERINFO_ENCODE_SET);
|
||||
let value = percent_encode(c.value().as_bytes(), USERINFO_ENCODE_SET);
|
||||
let _ = write!(&mut cookie, "; {}={}", name, value);
|
||||
}
|
||||
if !cookie.is_empty() {
|
||||
head.headers.insert(
|
||||
header::SET_COOKIE,
|
||||
HeaderValue::from_str(&cookie.as_str()[2..]).unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(pl) = self.payload {
|
||||
|
@ -1,14 +1,15 @@
|
||||
//! Websockets client
|
||||
use std::fmt::Write as FmtWrite;
|
||||
use std::io::Write;
|
||||
use std::rc::Rc;
|
||||
use std::{fmt, str};
|
||||
|
||||
use actix_codec::Framed;
|
||||
use actix_http::cookie::{Cookie, CookieJar};
|
||||
use actix_http::{ws, Payload, RequestHead};
|
||||
use bytes::{BufMut, BytesMut};
|
||||
#[cfg(feature = "cookies")]
|
||||
use cookie::{Cookie, CookieJar};
|
||||
use futures::future::{err, Either, Future};
|
||||
use percent_encoding::{percent_encode, USERINFO_ENCODE_SET};
|
||||
use tokio_timer::Timeout;
|
||||
|
||||
pub use actix_http::ws::{CloseCode, CloseReason, Codec, Frame, Message};
|
||||
@ -33,7 +34,6 @@ pub struct WebsocketsRequest {
|
||||
max_size: usize,
|
||||
server_mode: bool,
|
||||
default_headers: bool,
|
||||
#[cfg(feature = "cookies")]
|
||||
cookies: Option<CookieJar>,
|
||||
config: Rc<ClientConfig>,
|
||||
}
|
||||
@ -62,7 +62,6 @@ impl WebsocketsRequest {
|
||||
protocols: None,
|
||||
max_size: 65_536,
|
||||
server_mode: false,
|
||||
#[cfg(feature = "cookies")]
|
||||
cookies: None,
|
||||
default_headers: true,
|
||||
}
|
||||
@ -82,7 +81,6 @@ impl WebsocketsRequest {
|
||||
self
|
||||
}
|
||||
|
||||
#[cfg(feature = "cookies")]
|
||||
/// Set a cookie
|
||||
pub fn cookie<'c>(mut self, cookie: Cookie<'c>) -> Self {
|
||||
if self.cookies.is_none() {
|
||||
@ -264,28 +262,20 @@ impl WebsocketsRequest {
|
||||
self
|
||||
};
|
||||
|
||||
#[allow(unused_mut)]
|
||||
let mut head = slf.head;
|
||||
|
||||
#[cfg(feature = "cookies")]
|
||||
{
|
||||
use percent_encoding::{percent_encode, USERINFO_ENCODE_SET};
|
||||
use std::fmt::Write;
|
||||
|
||||
// set cookies
|
||||
if let Some(ref mut jar) = slf.cookies {
|
||||
let mut cookie = String::new();
|
||||
for c in jar.delta() {
|
||||
let name = percent_encode(c.name().as_bytes(), USERINFO_ENCODE_SET);
|
||||
let value =
|
||||
percent_encode(c.value().as_bytes(), USERINFO_ENCODE_SET);
|
||||
let _ = write!(&mut cookie, "; {}={}", name, value);
|
||||
}
|
||||
head.headers.insert(
|
||||
header::COOKIE,
|
||||
HeaderValue::from_str(&cookie.as_str()[2..]).unwrap(),
|
||||
);
|
||||
// set cookies
|
||||
if let Some(ref mut jar) = slf.cookies {
|
||||
let mut cookie = String::new();
|
||||
for c in jar.delta() {
|
||||
let name = percent_encode(c.name().as_bytes(), USERINFO_ENCODE_SET);
|
||||
let value = percent_encode(c.value().as_bytes(), USERINFO_ENCODE_SET);
|
||||
let _ = write!(&mut cookie, "; {}={}", name, value);
|
||||
}
|
||||
head.headers.insert(
|
||||
header::COOKIE,
|
||||
HeaderValue::from_str(&cookie.as_str()[2..]).unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
// origin
|
||||
|
Reference in New Issue
Block a user