1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-07-30 20:16:40 +02:00

Compare commits

..

9 Commits

Author SHA1 Message Date
Yuki Okushi
5b60ee8cfd Merge pull request #1534 from JohnTitor/next-codegen
codegen: Bump up to 0.2.2
2020-05-23 18:08:36 +09:00
Yuki Okushi
bb89d04080 codegen: Bump up to 0.2.2 2020-05-23 17:22:30 +09:00
Yuki Okushi
f57b5659da Merge pull request #1533 from JohnTitor/next-test-server
http-test: Bump up to 2.0.0-alpha.1
2020-05-23 15:22:40 +09:00
Yuki Okushi
4a955c425d Update actix-http-test dependency to 2.0.0-alpha.1 2020-05-23 12:14:17 +09:00
Yuki Okushi
905f86b540 http-test: Bump up to 2.0.0-alpha.1 2020-05-23 12:13:43 +09:00
Yuki Okushi
0348114ad8 Merge pull request #1532 from JohnTitor/issue-template
Add links to Gitter on the issue template
2020-05-23 12:11:59 +09:00
Yuki Okushi
9c5a2d6580 Add links to Gitter on the issue template 2020-05-22 13:14:01 +09:00
Yuki Okushi
2550f00702 Merge pull request #1530 from NickKolpinskiy/itoa
Use `itoa` in the content-length helper
2020-05-22 13:03:50 +09:00
Nick Kolpinskiy
7d8fb631a0 Use itoa in the content-length helper 2020-05-21 22:25:34 +03:00
12 changed files with 57 additions and 106 deletions

8
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@@ -0,0 +1,8 @@
blank_issues_enabled: true
contact_links:
- name: Gitter channel (actix-web)
url: https://gitter.im/actix/actix-web
about: Please ask and answer questions about the actix-web here.
- name: Gitter channel (actix)
url: https://gitter.im/actix/actix
about: Please ask and answer questions about the actix here.

View File

@@ -77,7 +77,7 @@ actix-macros = "0.1.0"
actix-threadpool = "0.3.1"
actix-tls = "2.0.0-alpha.1"
actix-web-codegen = "0.2.0"
actix-web-codegen = "0.2.2"
actix-http = "2.0.0-alpha.4"
awc = { version = "2.0.0-alpha.2", default-features = false }

View File

@@ -33,5 +33,5 @@ log = "0.4"
[dev-dependencies]
actix-server = "1.0.0"
actix-connect = { version = "2.0.0-alpha.2", features = ["openssl"] }
actix-http-test = { version = "1.0.0", features = ["openssl"] }
actix-http-test = { version = "2.0.0-alpha.1", features = ["openssl"] }
actix-utils = "1.0.3"

View File

@@ -64,6 +64,7 @@ h2 = "0.2.1"
http = "0.2.0"
httparse = "1.3"
indexmap = "1.3"
itoa = "0.4"
lazy_static = "1.4"
language-tags = "0.2"
log = "0.4"
@@ -89,7 +90,7 @@ flate2 = { version = "1.0.13", optional = true }
[dev-dependencies]
actix-server = "1.0.1"
actix-connect = { version = "2.0.0-alpha.2", features = ["openssl"] }
actix-http-test = { version = "1.0.0", features = ["openssl"] }
actix-http-test = { version = "2.0.0-alpha.1", features = ["openssl"] }
actix-tls = { version = "2.0.0-alpha.1", features = ["openssl"] }
criterion = "0.3"
env_logger = "0.7"

View File

@@ -25,6 +25,13 @@ fn bench_write_content_length(c: &mut Criterion) {
_new::write_content_length(i, &mut b)
})
});
group.bench_with_input(BenchmarkId::new("itoa", i), i, |b, &i| {
b.iter(|| {
let mut b = BytesMut::with_capacity(35);
_itoa::write_content_length(i, &mut b)
})
});
}
group.finish();
@@ -33,6 +40,23 @@ fn bench_write_content_length(c: &mut Criterion) {
criterion_group!(benches, bench_write_content_length);
criterion_main!(benches);
mod _itoa {
use bytes::{BufMut, BytesMut};
pub fn write_content_length(n: usize, bytes: &mut BytesMut) {
if n == 0 {
bytes.put_slice(b"\r\ncontent-length: 0\r\n");
return;
}
let mut buf = itoa::Buffer::new();
bytes.put_slice(b"\r\ncontent-length: ");
bytes.put_slice(buf.format(n).as_bytes());
bytes.put_slice(b"\r\n");
}
}
mod _new {
use bytes::{BufMut, BytesMut};

View File

@@ -31,103 +31,18 @@ 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: u64, bytes: &mut BytesMut) {
if n == 0 {
bytes.put_slice(b"\r\ncontent-length: 0\r\n");
return;
}
let mut buf = itoa::Buffer::new();
bytes.put_slice(b"\r\ncontent-length: ");
if n < 10 {
bytes.put_u8(DIGITS_START + (n as u8));
} else if n < 100 {
let n = n as u8;
let d10 = n / 10;
let d1 = n % 10;
bytes.put_u8(DIGITS_START + d10);
bytes.put_u8(DIGITS_START + d1);
} else if n < 1000 {
let n = n as u16;
let d100 = (n / 100) as u8;
let d10 = ((n / 10) % 10) as u8;
let d1 = (n % 10) as u8;
bytes.put_u8(DIGITS_START + d100);
bytes.put_u8(DIGITS_START + d10);
bytes.put_u8(DIGITS_START + d1);
} else if n < 10_000 {
let n = n as u16;
let d1000 = (n / 1000) as u8;
let d100 = ((n / 100) % 10) as u8;
let d10 = ((n / 10) % 10) as u8;
let d1 = (n % 10) as u8;
bytes.put_u8(DIGITS_START + d1000);
bytes.put_u8(DIGITS_START + d100);
bytes.put_u8(DIGITS_START + d10);
bytes.put_u8(DIGITS_START + d1);
} else if n < 100_000 {
let n = n as u32;
let d10000 = (n / 10000) as u8;
let d1000 = ((n / 1000) % 10) as u8;
let d100 = ((n / 100) % 10) as u8;
let d10 = ((n / 10) % 10) as u8;
let d1 = (n % 10) as u8;
bytes.put_u8(DIGITS_START + d10000);
bytes.put_u8(DIGITS_START + d1000);
bytes.put_u8(DIGITS_START + d100);
bytes.put_u8(DIGITS_START + d10);
bytes.put_u8(DIGITS_START + d1);
} else if n < 1_000_000 {
let n = n as u32;
let d100000 = (n / 100_000) as u8;
let d10000 = ((n / 10000) % 10) as u8;
let d1000 = ((n / 1000) % 10) as u8;
let d100 = ((n / 100) % 10) as u8;
let d10 = ((n / 10) % 10) as u8;
let d1 = (n % 10) as u8;
bytes.put_u8(DIGITS_START + d100000);
bytes.put_u8(DIGITS_START + d10000);
bytes.put_u8(DIGITS_START + d1000);
bytes.put_u8(DIGITS_START + d100);
bytes.put_u8(DIGITS_START + d10);
bytes.put_u8(DIGITS_START + d1);
} else {
write_u64(n, bytes);
}
bytes.put_slice(buf.format(n).as_bytes());
bytes.put_slice(b"\r\n");
}
pub(crate) fn write_u64(n: u64, bytes: &mut BytesMut) {
let mut n = n;
// 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);
while n > 9 {
// "pop" the least-significant digit
let lsd = (n % 10) as u8;
// remove the lsd from n
n /= 10;
buf.put_u8(DIGITS_START + lsd);
}
// put msd to result buffer
bytes.put_u8(DIGITS_START + (n as u8));
// put, in reverse (msd to lsd), remaining digits to buffer
for i in (0..buf.len()).rev() {
bytes.put_u8(buf[i]);
}
}
pub(crate) struct Writer<'a>(pub &'a mut BytesMut);
impl<'a> io::Write for Writer<'a> {

View File

@@ -1,8 +1,10 @@
# Changes
## [Unreleased] - 2020-xx-xx
## [0.2.2] - 2020-05-23
* Bump minimum supported Rust version to 1.40
* Add resource middleware on actix-web-codegen [#1467]
[#1467]: https://github.com/actix/actix-web/pull/1467
## [0.2.1] - 2020-02-25

View File

@@ -1,6 +1,6 @@
[package]
name = "actix-web-codegen"
version = "0.2.1"
version = "0.2.2"
description = "Actix web proc macros"
readme = "README.md"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
@@ -12,9 +12,9 @@ workspace = ".."
proc-macro = true
[dependencies]
quote = "^1"
syn = { version = "^1", features = ["full", "parsing"] }
proc-macro2 = "^1"
quote = "1"
syn = { version = "1", features = ["full", "parsing"] }
proc-macro2 = "1"
[dev-dependencies]
actix-rt = "1.0.0"

View File

@@ -57,7 +57,7 @@ rust-tls = { version = "0.17.0", package = "rustls", optional = true, features =
actix-connect = { version = "2.0.0-alpha.2", features = ["openssl"] }
actix-web = { version = "3.0.0-alpha.3", features = ["openssl"] }
actix-http = { version = "2.0.0-alpha.4", features = ["openssl"] }
actix-http-test = { version = "1.0.0", features = ["openssl"] }
actix-http-test = { version = "2.0.0-alpha.1", features = ["openssl"] }
actix-utils = "1.0.3"
actix-server = "1.0.0"
actix-tls = { version = "2.0.0-alpha.1", features = ["openssl", "rustls"] }

View File

@@ -1,6 +1,6 @@
# Changes
## [Unreleased] - 2020-xx-xx
## [2.0.0-alpha.1] - 2020-05-23
* Update the `time` dependency to 0.2.7
* Update `actix-connect` dependency to 2.0.0-alpha.2

View File

@@ -1,6 +1,6 @@
[package]
name = "actix-http-test"
version = "1.0.0"
version = "2.0.0-alpha.1"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix http test server"
readme = "README.md"

View File

@@ -104,7 +104,8 @@ pub async fn test_server<F: ServiceFactory<TcpStream>>(factory: F) -> TestServer
/// Get first available unused address
pub fn unused_addr() -> net::SocketAddr {
let addr: net::SocketAddr = "127.0.0.1:0".parse().unwrap();
let socket = Socket::new(Domain::ipv4(), Type::stream(), Some(Protocol::tcp())).unwrap();
let socket =
Socket::new(Domain::ipv4(), Type::stream(), Some(Protocol::tcp())).unwrap();
socket.bind(&addr.into()).unwrap();
socket.set_reuse_address(true).unwrap();
let tcp = socket.into_tcp_listener();