1
0
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:
Yuki Okushi 2020-05-18 10:40:01 +09:00 committed by GitHub
commit 426a9b5d4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 22 additions and 48 deletions

View File

@ -3,9 +3,13 @@
* Setting a cookie's SameSite property, explicitly, to `SameSite::None` will now
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.
* actix-http support for Actors messages was moved to actix-http crate and is enabled
with feature `actors`
* `BodySize::Sized64` variant has been removed. `BodySize::Sized` now receives a
`u64` instead of a `usize`.
## 2.0.0
* `HttpServer::start()` renamed to `HttpServer::run()`. It also possible to

View File

@ -6,6 +6,9 @@
* 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
* Support parsing of `SameSite=None` [#1503]

View File

@ -15,8 +15,7 @@ use crate::error::Error;
pub enum BodySize {
None,
Empty,
Sized(usize),
Sized64(u64),
Sized(u64),
Stream,
}
@ -25,8 +24,7 @@ impl BodySize {
match self {
BodySize::None
| BodySize::Empty
| BodySize::Sized(0)
| BodySize::Sized64(0) => true,
| BodySize::Sized(0) => true,
_ => false,
}
}
@ -170,7 +168,7 @@ impl MessageBody for Body {
match self {
Body::None => BodySize::None,
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(),
}
}
@ -297,7 +295,7 @@ where
impl MessageBody for Bytes {
fn size(&self) -> BodySize {
BodySize::Sized(self.len())
BodySize::Sized(self.len() as u64)
}
fn poll_next(
@ -314,7 +312,7 @@ impl MessageBody for Bytes {
impl MessageBody for BytesMut {
fn size(&self) -> BodySize {
BodySize::Sized(self.len())
BodySize::Sized(self.len() as u64)
}
fn poll_next(
@ -331,7 +329,7 @@ impl MessageBody for BytesMut {
impl MessageBody for &'static str {
fn size(&self) -> BodySize {
BodySize::Sized(self.len())
BodySize::Sized(self.len() as u64)
}
fn poll_next(
@ -350,7 +348,7 @@ impl MessageBody for &'static str {
impl MessageBody for Vec<u8> {
fn size(&self) -> BodySize {
BodySize::Sized(self.len())
BodySize::Sized(self.len() as u64)
}
fn poll_next(
@ -367,7 +365,7 @@ impl MessageBody for Vec<u8> {
impl MessageBody for String {
fn size(&self) -> BodySize {
BodySize::Sized(self.len())
BodySize::Sized(self.len() as u64)
}
fn poll_next(
@ -458,7 +456,7 @@ where
S: Stream<Item = Result<Bytes, Error>> + Unpin,
{
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`].

View File

@ -64,10 +64,6 @@ where
CONTENT_LENGTH,
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.

View File

@ -4,7 +4,7 @@ use std::ptr::copy_nonoverlapping;
use std::slice::from_raw_parts_mut;
use std::{cmp, io};
use bytes::{buf::BufMutExt, BufMut, BytesMut};
use bytes::{BufMut, BytesMut};
use crate::body::BodySize;
use crate::config::ServiceConfig;
@ -95,15 +95,6 @@ pub(crate) trait MessageType: Sized {
}
}
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"),
}
@ -338,8 +329,7 @@ impl<T: MessageType> MessageEncoder<T> {
if !head {
self.te = match length {
BodySize::Empty => TransferEncoding::empty(),
BodySize::Sized(len) => TransferEncoding::length(len as u64),
BodySize::Sized64(len) => TransferEncoding::length(len),
BodySize::Sized(len) => TransferEncoding::length(len),
BodySize::Stream => {
if message.chunked() && !stream {
TransferEncoding::chunked()
@ -582,19 +572,6 @@ mod tests {
assert!(data.contains("Content-Type: plain/text\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();
head.set_camel_case_headers(false);
head.headers.insert(DATE, HeaderValue::from_static("date"));

View File

@ -210,10 +210,6 @@ where
CONTENT_LENGTH,
HeaderValue::try_from(format!("{}", len)).unwrap(),
),
BodySize::Sized64(len) => res.headers_mut().insert(
CONTENT_LENGTH,
HeaderValue::try_from(format!("{}", len)).unwrap(),
),
};
// copy headers

View File

@ -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
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: ");
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 + d1);
} else {
write_usize(n, bytes);
write_u64(n, bytes);
}
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;
// 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
let mut buf = BytesMut::with_capacity(20);