mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 00:21:08 +01:00
Merge pull request #1514 from actix/remove/sized64
remove needless BodySize::Sized64 variant
This commit is contained in:
commit
426a9b5d4d
@ -3,9 +3,13 @@
|
|||||||
* Setting a cookie's SameSite property, explicitly, to `SameSite::None` will now
|
* Setting a cookie's SameSite property, explicitly, to `SameSite::None` will now
|
||||||
result in `SameSite=None` being sent with the response Set-Cookie header.
|
result in `SameSite=None` being sent with the response Set-Cookie header.
|
||||||
To create a cookie without a SameSite attribute, remove any calls setting same_site.
|
To create a cookie without a SameSite attribute, remove any calls setting same_site.
|
||||||
|
|
||||||
* actix-http support for Actors messages was moved to actix-http crate and is enabled
|
* actix-http support for Actors messages was moved to actix-http crate and is enabled
|
||||||
with feature `actors`
|
with feature `actors`
|
||||||
|
|
||||||
|
* `BodySize::Sized64` variant has been removed. `BodySize::Sized` now receives a
|
||||||
|
`u64` instead of a `usize`.
|
||||||
|
|
||||||
## 2.0.0
|
## 2.0.0
|
||||||
|
|
||||||
* `HttpServer::start()` renamed to `HttpServer::run()`. It also possible to
|
* `HttpServer::start()` renamed to `HttpServer::run()`. It also possible to
|
||||||
|
@ -6,6 +6,9 @@
|
|||||||
|
|
||||||
* Bump minimum supported Rust version to 1.40
|
* Bump minimum supported Rust version to 1.40
|
||||||
|
|
||||||
|
* `BodySize::Sized64` variant has been removed. `BodySize::Sized` now receives a
|
||||||
|
`u64` instead of a `usize`.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
* Support parsing of `SameSite=None` [#1503]
|
* Support parsing of `SameSite=None` [#1503]
|
||||||
|
@ -15,8 +15,7 @@ use crate::error::Error;
|
|||||||
pub enum BodySize {
|
pub enum BodySize {
|
||||||
None,
|
None,
|
||||||
Empty,
|
Empty,
|
||||||
Sized(usize),
|
Sized(u64),
|
||||||
Sized64(u64),
|
|
||||||
Stream,
|
Stream,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,8 +24,7 @@ impl BodySize {
|
|||||||
match self {
|
match self {
|
||||||
BodySize::None
|
BodySize::None
|
||||||
| BodySize::Empty
|
| BodySize::Empty
|
||||||
| BodySize::Sized(0)
|
| BodySize::Sized(0) => true,
|
||||||
| BodySize::Sized64(0) => true,
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,7 +168,7 @@ impl MessageBody for Body {
|
|||||||
match self {
|
match self {
|
||||||
Body::None => BodySize::None,
|
Body::None => BodySize::None,
|
||||||
Body::Empty => BodySize::Empty,
|
Body::Empty => BodySize::Empty,
|
||||||
Body::Bytes(ref bin) => BodySize::Sized(bin.len()),
|
Body::Bytes(ref bin) => BodySize::Sized(bin.len() as u64),
|
||||||
Body::Message(ref body) => body.size(),
|
Body::Message(ref body) => body.size(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -297,7 +295,7 @@ where
|
|||||||
|
|
||||||
impl MessageBody for Bytes {
|
impl MessageBody for Bytes {
|
||||||
fn size(&self) -> BodySize {
|
fn size(&self) -> BodySize {
|
||||||
BodySize::Sized(self.len())
|
BodySize::Sized(self.len() as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_next(
|
fn poll_next(
|
||||||
@ -314,7 +312,7 @@ impl MessageBody for Bytes {
|
|||||||
|
|
||||||
impl MessageBody for BytesMut {
|
impl MessageBody for BytesMut {
|
||||||
fn size(&self) -> BodySize {
|
fn size(&self) -> BodySize {
|
||||||
BodySize::Sized(self.len())
|
BodySize::Sized(self.len() as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_next(
|
fn poll_next(
|
||||||
@ -331,7 +329,7 @@ impl MessageBody for BytesMut {
|
|||||||
|
|
||||||
impl MessageBody for &'static str {
|
impl MessageBody for &'static str {
|
||||||
fn size(&self) -> BodySize {
|
fn size(&self) -> BodySize {
|
||||||
BodySize::Sized(self.len())
|
BodySize::Sized(self.len() as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_next(
|
fn poll_next(
|
||||||
@ -350,7 +348,7 @@ impl MessageBody for &'static str {
|
|||||||
|
|
||||||
impl MessageBody for Vec<u8> {
|
impl MessageBody for Vec<u8> {
|
||||||
fn size(&self) -> BodySize {
|
fn size(&self) -> BodySize {
|
||||||
BodySize::Sized(self.len())
|
BodySize::Sized(self.len() as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_next(
|
fn poll_next(
|
||||||
@ -367,7 +365,7 @@ impl MessageBody for Vec<u8> {
|
|||||||
|
|
||||||
impl MessageBody for String {
|
impl MessageBody for String {
|
||||||
fn size(&self) -> BodySize {
|
fn size(&self) -> BodySize {
|
||||||
BodySize::Sized(self.len())
|
BodySize::Sized(self.len() as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_next(
|
fn poll_next(
|
||||||
@ -458,7 +456,7 @@ where
|
|||||||
S: Stream<Item = Result<Bytes, Error>> + Unpin,
|
S: Stream<Item = Result<Bytes, Error>> + Unpin,
|
||||||
{
|
{
|
||||||
fn size(&self) -> BodySize {
|
fn size(&self) -> BodySize {
|
||||||
BodySize::Sized64(self.size)
|
BodySize::Sized(self.size as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempts to pull out the next value of the underlying [`Stream`].
|
/// Attempts to pull out the next value of the underlying [`Stream`].
|
||||||
|
@ -64,10 +64,6 @@ where
|
|||||||
CONTENT_LENGTH,
|
CONTENT_LENGTH,
|
||||||
HeaderValue::try_from(format!("{}", len)).unwrap(),
|
HeaderValue::try_from(format!("{}", len)).unwrap(),
|
||||||
),
|
),
|
||||||
BodySize::Sized64(len) => req.headers_mut().insert(
|
|
||||||
CONTENT_LENGTH,
|
|
||||||
HeaderValue::try_from(format!("{}", len)).unwrap(),
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Extracting extra headers from RequestHeadType. HeaderMap::new() does not allocate.
|
// Extracting extra headers from RequestHeadType. HeaderMap::new() does not allocate.
|
||||||
|
@ -4,7 +4,7 @@ use std::ptr::copy_nonoverlapping;
|
|||||||
use std::slice::from_raw_parts_mut;
|
use std::slice::from_raw_parts_mut;
|
||||||
use std::{cmp, io};
|
use std::{cmp, io};
|
||||||
|
|
||||||
use bytes::{buf::BufMutExt, BufMut, BytesMut};
|
use bytes::{BufMut, BytesMut};
|
||||||
|
|
||||||
use crate::body::BodySize;
|
use crate::body::BodySize;
|
||||||
use crate::config::ServiceConfig;
|
use crate::config::ServiceConfig;
|
||||||
@ -95,15 +95,6 @@ pub(crate) trait MessageType: Sized {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
BodySize::Sized(len) => helpers::write_content_length(len, dst),
|
BodySize::Sized(len) => helpers::write_content_length(len, dst),
|
||||||
BodySize::Sized64(len) => {
|
|
||||||
if camel_case {
|
|
||||||
dst.put_slice(b"\r\nContent-Length: ");
|
|
||||||
} else {
|
|
||||||
dst.put_slice(b"\r\ncontent-length: ");
|
|
||||||
}
|
|
||||||
#[allow(clippy::write_with_newline)]
|
|
||||||
write!(dst.writer(), "{}\r\n", len)?;
|
|
||||||
}
|
|
||||||
BodySize::None => dst.put_slice(b"\r\n"),
|
BodySize::None => dst.put_slice(b"\r\n"),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,8 +329,7 @@ impl<T: MessageType> MessageEncoder<T> {
|
|||||||
if !head {
|
if !head {
|
||||||
self.te = match length {
|
self.te = match length {
|
||||||
BodySize::Empty => TransferEncoding::empty(),
|
BodySize::Empty => TransferEncoding::empty(),
|
||||||
BodySize::Sized(len) => TransferEncoding::length(len as u64),
|
BodySize::Sized(len) => TransferEncoding::length(len),
|
||||||
BodySize::Sized64(len) => TransferEncoding::length(len),
|
|
||||||
BodySize::Stream => {
|
BodySize::Stream => {
|
||||||
if message.chunked() && !stream {
|
if message.chunked() && !stream {
|
||||||
TransferEncoding::chunked()
|
TransferEncoding::chunked()
|
||||||
@ -582,19 +572,6 @@ mod tests {
|
|||||||
assert!(data.contains("Content-Type: plain/text\r\n"));
|
assert!(data.contains("Content-Type: plain/text\r\n"));
|
||||||
assert!(data.contains("Date: date\r\n"));
|
assert!(data.contains("Date: date\r\n"));
|
||||||
|
|
||||||
let _ = head.encode_headers(
|
|
||||||
&mut bytes,
|
|
||||||
Version::HTTP_11,
|
|
||||||
BodySize::Sized64(100),
|
|
||||||
ConnectionType::KeepAlive,
|
|
||||||
&ServiceConfig::default(),
|
|
||||||
);
|
|
||||||
let data =
|
|
||||||
String::from_utf8(Vec::from(bytes.split().freeze().as_ref())).unwrap();
|
|
||||||
assert!(data.contains("Content-Length: 100\r\n"));
|
|
||||||
assert!(data.contains("Content-Type: plain/text\r\n"));
|
|
||||||
assert!(data.contains("Date: date\r\n"));
|
|
||||||
|
|
||||||
let mut head = RequestHead::default();
|
let mut head = RequestHead::default();
|
||||||
head.set_camel_case_headers(false);
|
head.set_camel_case_headers(false);
|
||||||
head.headers.insert(DATE, HeaderValue::from_static("date"));
|
head.headers.insert(DATE, HeaderValue::from_static("date"));
|
||||||
|
@ -210,10 +210,6 @@ where
|
|||||||
CONTENT_LENGTH,
|
CONTENT_LENGTH,
|
||||||
HeaderValue::try_from(format!("{}", len)).unwrap(),
|
HeaderValue::try_from(format!("{}", len)).unwrap(),
|
||||||
),
|
),
|
||||||
BodySize::Sized64(len) => res.headers_mut().insert(
|
|
||||||
CONTENT_LENGTH,
|
|
||||||
HeaderValue::try_from(format!("{}", len)).unwrap(),
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// copy headers
|
// copy headers
|
||||||
|
@ -30,7 +30,7 @@ pub(crate) fn write_status_line(version: Version, n: u16, bytes: &mut BytesMut)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// NOTE: bytes object has to contain enough space
|
/// NOTE: bytes object has to contain enough space
|
||||||
pub fn write_content_length(n: usize, bytes: &mut BytesMut) {
|
pub fn write_content_length(n: u64, bytes: &mut BytesMut) {
|
||||||
bytes.put_slice(b"\r\ncontent-length: ");
|
bytes.put_slice(b"\r\ncontent-length: ");
|
||||||
|
|
||||||
if n < 10 {
|
if n < 10 {
|
||||||
@ -96,16 +96,16 @@ pub fn write_content_length(n: usize, bytes: &mut BytesMut) {
|
|||||||
bytes.put_u8(DIGITS_START + d10);
|
bytes.put_u8(DIGITS_START + d10);
|
||||||
bytes.put_u8(DIGITS_START + d1);
|
bytes.put_u8(DIGITS_START + d1);
|
||||||
} else {
|
} else {
|
||||||
write_usize(n, bytes);
|
write_u64(n, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes.put_slice(b"\r\n");
|
bytes.put_slice(b"\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn write_usize(n: usize, bytes: &mut BytesMut) {
|
pub(crate) fn write_u64(n: u64, bytes: &mut BytesMut) {
|
||||||
let mut n = n;
|
let mut n = n;
|
||||||
|
|
||||||
// 20 chars is max length of a usize (2^64)
|
// 20 chars is max length of a u64 (2^64)
|
||||||
// digits will be added to the buffer from lsd to msd
|
// digits will be added to the buffer from lsd to msd
|
||||||
let mut buf = BytesMut::with_capacity(20);
|
let mut buf = BytesMut::with_capacity(20);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user