Skip to content

Commit f59401f

Browse files
author
Mark Lodato
committed
Increase URI MAX_LEN to 150_000
**This Commit** Increases the max length of URIs to be 150_000 **Why?** STEM can receive requests > u16::MAX. When it tries to forward these requests to Impeller, `reqwest` crashes when parsing the URL into a URI because `http` returns a `Result::Err`. This is currently being tracked [here](seanmonstar/reqwest#668).
1 parent 6443bdb commit f59401f

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

src/header/map.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,10 @@ impl<T> HeaderMap<T> {
629629
/// ```
630630
pub fn reserve(&mut self, additional: usize) {
631631
// TODO: This can't overflow if done properly... since the max # of
632-
// elements is u16::MAX.
633-
let cap = self.entries.len()
632+
// elements is 150_000
633+
let cap = self
634+
.entries
635+
.len()
634636
.checked_add(additional)
635637
.expect("reserve overflow");
636638

src/uri/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ enum ErrorKind {
147147
SchemeTooLong,
148148
}
149149

150-
// u16::MAX is reserved for None
151-
const MAX_LEN: usize = (u16::MAX - 1) as usize;
150+
// 150_001 is for NONE
151+
const MAX_LEN: usize = 150_000;
152152

153153
const URI_CHARS: [u8; 256] = [
154154
// 0 1 2 3 4 5 6 7 8 9

src/uri/path.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use super::{ErrorKind, InvalidUri, InvalidUriBytes};
1111
#[derive(Clone)]
1212
pub struct PathAndQuery {
1313
pub(super) data: ByteStr,
14-
pub(super) query: u16,
14+
pub(super) query: u32,
1515
}
1616

17-
const NONE: u16 = ::std::u16::MAX;
17+
const NONE: u32 = 150_001;
1818

1919
impl PathAndQuery {
2020
/// Attempt to convert a `PathAndQuery` from `Bytes`.
@@ -57,7 +57,7 @@ impl PathAndQuery {
5757
match b {
5858
b'?' => {
5959
debug_assert_eq!(query, NONE);
60-
query = i as u16;
60+
query = i as u32;
6161
break;
6262
}
6363
b'#' => {

src/uri/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ fn test_uri_parse_error() {
445445
fn test_max_uri_len() {
446446
let mut uri = vec![];
447447
uri.extend(b"http://localhost/");
448-
uri.extend(vec![b'a'; 70 * 1024]);
448+
uri.extend(vec![b'a'; 150_001]);
449449

450450
let uri = String::from_utf8(uri).unwrap();
451451
let res: Result<Uri, InvalidUri> = uri.parse();

0 commit comments

Comments
 (0)