chore: checkpoint before Python removal

This commit is contained in:
2026-03-26 22:33:59 +00:00
parent 683cec9307
commit e568ddf82a
29972 changed files with 11269302 additions and 2 deletions

1
vendor/httparse/.cargo-checksum.json vendored Normal file
View File

@@ -0,0 +1 @@
{"files":{".cargo_vcs_info.json":"304c6a5cc4e924fef4ca4629de055fdf731825833e6a0764aa03e4581580297c",".github/FUNDING.yml":"e65635279e36972a4cecce26f3bb8115c09fd6d5d3e3e79d11a973877d4600a8",".github/workflows/ci.yml":"1045b35d3703f490e153c9a8513acf22496d5a3b0659fee70784c3cf425cb0f5",".github/workflows/cibench.yml":"3b09cf335f208b52d97ccb9a1ca803cece87c80a9b859b8236b9f4e25ab75456",".github/workflows/cifuzz.yml":"7814b157965db6452cba4ff3ebe30555c002daaff4baf46a985fa232cb768def","Cargo.lock":"ec51aecd295189c21ca216e1bb6e1f04e9f45d7dfc62da5c00480aebbf87a515","Cargo.toml":"067da5f6334526ce5f080909e5c271dd0968ab4198a65eea51d93b242febb48a","Cargo.toml.orig":"3a0da8a3d1c3ab896e16182c9a876b4ad4c265faa3042cde693621ea95c94060","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"391a5396cec6230bfabd4ef4eb2350eb895bc5efce377a2218f5702ed020d3e3","README.md":"eb23916ad2e4e904ee31e2af02e71ffd8f2d0c97f9e529f3e02f300a120e2c8b","benches/parse.rs":"1c76d3831410e0c2da0cbbee43431c2d28e2f1969664dea2a6a0e81f0a1c88be","build.rs":"eba8e341d746a6cf54249c62afe9eb237e7c21fcf9937223e894549e3a34d489","clippy.toml":"fd62dce2727b03fd4a8f6f3241e9da1e24ac2ff053d3986b0576c140823ec1ea","src/iter.rs":"630132d2d6fafa80c126b7b20b097c5ac7215575f7b61c8f8d7101b58ca57d0a","src/lib.rs":"a8307ce632f27b095cb84de27cfd8fc237977075d3eed41041f463c6afd9b757","src/macros.rs":"4e152282a120ec322f0873c65d2c334d7161f0085e91c52d45793c87f83e3e5c","src/simd/avx2.rs":"ce35db9ab9783880f44786a9d65727b0c5862a957d845e9f3d8a358b3ca4b01a","src/simd/mod.rs":"4fe941717937542c4c88eb95ffefb26db8492e4b5a1d46696fce0b5329702a21","src/simd/neon.rs":"fed66a5d37873dbf901ad2b69e9d08711c570a4a5fc958e13539808501ec9ac3","src/simd/runtime.rs":"fec921120b04042d9c3dbc78ced3477e112f16e4d06be68ac8d50ddce54b8da7","src/simd/sse42.rs":"04c1c6f29375eb87d0e7712deadd9ba3c94d20525b67ff869a266cc6b75cedf6","src/simd/swar.rs":"24d15cfaa7b1ac8f2a5ff74a590eb0e9f0c87de6058c2c65919e33f9f1923080","tests/uri.rs":"62664aa2db82b2b24174ef74b7b00b675806608bfcb64763f97b639b62dd3701"},"package":"6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87"}

6
vendor/httparse/.cargo_vcs_info.json vendored Normal file
View File

@@ -0,0 +1,6 @@
{
"git": {
"sha1": "9f29e79f9832dbd0ae5220acb17c1866745bdecd"
},
"path_in_vcs": ""
}

1
vendor/httparse/.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1 @@
github: [seanmonstar]

281
vendor/httparse/.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,281 @@
name: CI
on:
pull_request:
push:
branches:
- master
env:
RUST_BACKTRACE: 1
jobs:
ci-pass:
name: CI is green
runs-on: ubuntu-latest
needs:
- test
- simd
- check_x86
- aarch64
- msrv_x64
- msrv_aarch64
- miri
- clippy_check
steps:
- run: exit 0
test:
name: Test ${{ matrix.rust }} on ${{ matrix.os }}
strategy:
matrix:
rust:
- stable
- beta
- nightly
os:
- ubuntu-latest
- windows-latest
- macOS-latest
include:
- rust: nightly
benches: true
runs-on: ${{ matrix.os }}
env:
CARGO_CFG_HTTPARSE_DISABLE_SIMD: 1
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Install Rust (${{ matrix.rust }})
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- name: no_std
uses: actions-rs/cargo@v1
with:
command: build
args: --no-default-features
- name: Test
uses: actions-rs/cargo@v1
with:
command: test
- name: Test all benches
if: matrix.benches
uses: actions-rs/cargo@v1
with:
command: test
args: --benches
simd:
name: SIMD ${{ matrix.target_feature }} on ${{ matrix.rust }}
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- beta
- nightly
target_feature:
- "+sse4.2"
- "+avx2"
- "+sse4.2,+avx2"
disable_compiletime:
- 0
- 1
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Install Rust (${{ matrix.rust }})
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- name: Test
uses: actions-rs/cargo@v1
with:
command: test
env:
RUSTFLAGS: -C target_feature=${{ matrix.target_feature }}
CARGO_CFG_HTTPARSE_DISABLE_SIMD_COMPILETIME: ${{ matrix.disable_compiletime }}
check_x86:
name: check x86
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
target: i686-unknown-linux-musl
- name: Test without SIMD
uses: actions-rs/cargo@v1
with:
command: test
args: --target i686-unknown-linux-musl
env:
CARGO_CFG_HTTPARSE_DISABLE_SIMD_COMPILETIME: 1
- name: Test
uses: actions-rs/cargo@v1
with:
command: test
args: --target i686-unknown-linux-musl
msrv_x64:
name: msrv (x64)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.47.0
override: true
# Only build, dev-dependencies don't compile on 1.47.0
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
# This tests that aarch64 gracefully fallbacks to SWAR if neon_intrinsics aren't available (<1.59)
msrv_aarch64:
name: msrv (aarch64)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Install cross-compiling dependencies
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.47.0
override: true
target: aarch64-unknown-linux-gnu
# Only build, dev-dependencies don't compile on 1.47.0
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --target aarch64-unknown-linux-gnu
clippy_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run clippy
run: cargo clippy --all-targets --all-features
miri:
name: Test with Miri
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: miri
override: true
- name: Test
run: cargo miri test
#
# mirai:
# name: MIRAI static analysis
# runs-on: ubuntu-latest
#
# steps:
# - name: Checkout
# uses: actions/checkout@v1
#
# - name: Install Rust
# uses: actions-rs/toolchain@v1
# with:
# profile: minimal
# toolchain: nightly-2023-05-09
# components: clippy, rustfmt, rustc-dev, rust-src, rust-std, llvm-tools-preview
# override: true
#
# - name: install mirai
# run: cargo install --locked --git https://github.com/facebookexperimental/MIRAI/ mirai
# env:
# # MIRAI_FLAGS: --diag=(default|verify|library|paranoid)
# MIRAI_FLAGS: --diag=default
#
# - name: cargo mirai
# run: cargo mirai --lib
aarch64:
name: Test aarch64 (neon)
runs-on: ubuntu-latest
env:
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
target: aarch64-unknown-linux-gnu
- name: Install QEMU and dependencies
run: |
sudo apt-get update
sudo apt-get install -y qemu-user gcc-aarch64-linux-gnu
- name: Build tests
run: cargo build --tests --target aarch64-unknown-linux-gnu
- name: Run tests with QEMU
run: |
test_binaries=$(find target/aarch64-unknown-linux-gnu/debug/deps/ -type f -executable -name 'httparse-*')
if [ -n "$test_binaries" ]; then
for test_binary in $test_binaries
do
echo "Running tests in ${test_binary}"
/usr/bin/qemu-aarch64 -L /usr/aarch64-linux-gnu/ "${test_binary}"
done
else
echo "No test binaries found."
fi

View File

@@ -0,0 +1,123 @@
name: CI Benchmarks
on:
pull_request:
branches: [master]
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-C target-cpu=native"
jobs:
benchmark:
name: Run benchmarks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install critcmp
run: cargo install critcmp
- name: Run benchmarks (master)
run: |
git checkout master
cargo bench --bench parse -- --save-baseline master
- name: Run benchmarks (PR)
run: |
git checkout ${{ github.event.pull_request.head.sha }}
cargo bench --bench parse -- --save-baseline pr-${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.sha }}
- name: Compare benchmarks
run: |
critcmp -t 5 master pr-${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.sha }}
benchmark-x64:
name: Run x64 benchmarks
runs-on: ubuntu-latest
strategy:
matrix:
feature: [swar, sse42, avx2]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install critcmp
run: cargo install critcmp
- name: Run benchmarks (master)
run: |
git checkout master
cargo bench --bench parse -- --save-baseline master-${{ matrix.feature }}
env:
CARGO_CFG_HTTPARSE_DISABLE_SIMD: ${{ matrix.feature == 'swar' && '1' || '0' }}
RUSTFLAGS: ${{ matrix.feature != 'swar' && format('-C target-feature=+{0}', matrix.feature) || '' }}
- name: Run benchmarks (PR)
run: |
git checkout ${{ github.event.pull_request.head.sha }}
cargo bench --bench parse -- --save-baseline pr-${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.sha }}-${{ matrix.feature }}
env:
CARGO_CFG_HTTPARSE_DISABLE_SIMD: ${{ matrix.feature == 'swar' && '1' || '0' }}
RUSTFLAGS: ${{ matrix.feature != 'swar' && format('-C target-feature=+{0}', matrix.feature) || '' }}
- name: Compare benchmarks
run: |
critcmp -t 5 master-${{ matrix.feature }} pr-${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.sha }}-${{ matrix.feature }}
benchmark-aarch64:
name: Run aarch64 benchmarks
runs-on: macos-latest
strategy:
matrix:
feature: [swar, neon]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install critcmp
run: cargo install critcmp
- name: Run benchmarks (master)
run: |
git checkout master
cargo bench --bench parse -- --save-baseline master-aarch64-${{ matrix.feature }}
env:
CARGO_CFG_HTTPARSE_DISABLE_SIMD: ${{ matrix.feature == 'swar' && '1' || '0' }}
RUSTFLAGS: ${{ matrix.feature == 'neon' && '-C target-feature=+neon' || '' }}
- name: Run benchmarks (PR)
run: |
git checkout ${{ github.event.pull_request.head.sha }}
cargo bench --bench parse -- --save-baseline pr-${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.sha }}-aarch64-${{ matrix.feature }}
env:
CARGO_CFG_HTTPARSE_DISABLE_SIMD: ${{ matrix.feature == 'swar' && '1' || '0' }}
RUSTFLAGS: ${{ matrix.feature == 'neon' && '-C target-feature=+neon' || '' }}
- name: Compare benchmarks
run: |
critcmp -t 5 master-aarch64-${{ matrix.feature }} pr-${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.sha }}-aarch64-${{ matrix.feature }}

View File

@@ -0,0 +1,26 @@
name: CIFuzz
on: [pull_request]
jobs:
Fuzzing:
runs-on: ubuntu-latest
steps:
- name: Build Fuzzers
id: build
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
with:
oss-fuzz-project-name: 'httparse'
dry-run: false
language: rust
- name: Run Fuzzers
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
with:
oss-fuzz-project-name: 'httparse'
fuzz-seconds: 300
dry-run: false
language: rust
- name: Upload Crash
uses: actions/upload-artifact@v4
if: failure() && steps.build.outcome == 'success'
with:
name: artifacts
path: ./out/artifacts

688
vendor/httparse/Cargo.lock generated vendored Normal file
View File

@@ -0,0 +1,688 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bstr"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
dependencies = [
"lazy_static",
"memchr",
"regex-automata",
"serde",
]
[[package]]
name = "bumpalo"
version = "3.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3"
[[package]]
name = "byteorder"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "cast"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "2.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
dependencies = [
"bitflags",
"textwrap",
"unicode-width",
]
[[package]]
name = "criterion"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b01d6de93b2b6c65e17c634a26653a29d107b3c98c607c765bf38d041531cd8f"
dependencies = [
"atty",
"cast",
"clap",
"criterion-plot",
"csv",
"itertools",
"lazy_static",
"num-traits",
"oorandom",
"plotters",
"rayon",
"regex",
"serde",
"serde_cbor",
"serde_derive",
"serde_json",
"tinytemplate",
"walkdir",
]
[[package]]
name = "criterion-plot"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2673cc8207403546f45f5fd319a974b1e6983ad1a3ee7e6041650013be041876"
dependencies = [
"cast",
"itertools",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521"
dependencies = [
"cfg-if",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-deque"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc"
dependencies = [
"cfg-if",
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "045ebe27666471bb549370b4b0b3e51b07f56325befa4284db65fc89c02511b1"
dependencies = [
"autocfg",
"cfg-if",
"crossbeam-utils",
"memoffset",
"once_cell",
"scopeguard",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc"
dependencies = [
"cfg-if",
"once_cell",
]
[[package]]
name = "csv"
version = "1.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1"
dependencies = [
"bstr",
"csv-core",
"itoa 0.4.8",
"ryu",
"serde",
]
[[package]]
name = "csv-core"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90"
dependencies = [
"memchr",
]
[[package]]
name = "either"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be"
[[package]]
name = "getrandom"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "half"
version = "1.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7"
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
name = "httparse"
version = "1.10.1"
dependencies = [
"criterion",
"rand",
]
[[package]]
name = "itertools"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3"
dependencies = [
"either",
]
[[package]]
name = "itoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
name = "itoa"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d"
[[package]]
name = "js-sys"
version = "0.3.59"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.169"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
[[package]]
name = "log"
version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if",
]
[[package]]
name = "memchr"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "memoffset"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
dependencies = [
"autocfg",
]
[[package]]
name = "num-traits"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1"
dependencies = [
"hermit-abi",
"libc",
]
[[package]]
name = "once_cell"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1"
[[package]]
name = "oorandom"
version = "11.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575"
[[package]]
name = "plotters"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9428003b84df1496fb9d6eeee9c5f8145cb41ca375eb0dad204328888832811f"
dependencies = [
"num-traits",
"plotters-backend",
"plotters-svg",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "plotters-backend"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "193228616381fecdc1224c62e96946dfbc73ff4384fba576e052ff8c1bea8142"
[[package]]
name = "plotters-svg"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0918736323d1baff32ee0eade54984f6f201ad7e97d5cfb5d6ab4a358529615"
dependencies = [
"plotters-backend",
]
[[package]]
name = "ppv-lite86"
version = "0.2.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04"
dependencies = [
"zerocopy",
]
[[package]]
name = "proc-macro2"
version = "1.0.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "rayon"
version = "1.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d"
dependencies = [
"autocfg",
"crossbeam-deque",
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f"
dependencies = [
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-utils",
"num_cpus",
]
[[package]]
name = "regex"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
dependencies = [
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
[[package]]
name = "regex-syntax"
version = "0.6.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
[[package]]
name = "ryu"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695"
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "serde"
version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc855a42c7967b7c369eb5860f7164ef1f6f81c20c7cc1141f2a604e18723b03"
[[package]]
name = "serde_cbor"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5"
dependencies = [
"half",
"serde",
]
[[package]]
name = "serde_derive"
version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f2122636b9fe3b81f1cb25099fcf2d3f542cdb1d45940d56c713158884a05da"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.98",
]
[[package]]
name = "serde_json"
version = "1.0.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7"
dependencies = [
"itoa 1.0.2",
"ryu",
"serde",
]
[[package]]
name = "syn"
version = "1.0.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.96"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "textwrap"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
dependencies = [
"unicode-width",
]
[[package]]
name = "tinytemplate"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc"
dependencies = [
"serde",
"serde_json",
]
[[package]]
name = "unicode-ident"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7"
[[package]]
name = "unicode-width"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
[[package]]
name = "walkdir"
version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56"
dependencies = [
"same-file",
"winapi",
"winapi-util",
]
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
"syn 1.0.98",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.98",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a"
[[package]]
name = "web-sys"
version = "0.3.59"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1"
dependencies = [
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "zerocopy"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
dependencies = [
"byteorder",
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.96",
]

77
vendor/httparse/Cargo.toml vendored Normal file
View File

@@ -0,0 +1,77 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2018"
name = "httparse"
version = "1.10.1"
authors = ["Sean McArthur <sean@seanmonstar.com>"]
build = "build.rs"
autolib = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "A tiny, safe, speedy, zero-copy HTTP/1.x parser."
documentation = "https://docs.rs/httparse"
readme = "README.md"
keywords = [
"http",
"parser",
"no_std",
]
categories = [
"network-programming",
"no-std",
"parser-implementations",
"web-programming",
]
license = "MIT OR Apache-2.0"
repository = "https://github.com/seanmonstar/httparse"
[features]
default = ["std"]
std = []
[lib]
name = "httparse"
path = "src/lib.rs"
bench = false
[[test]]
name = "uri"
path = "tests/uri.rs"
[[bench]]
name = "parse"
path = "benches/parse.rs"
harness = false
[dev-dependencies.criterion]
version = "0.3.5"
[dev-dependencies.rand]
version = "0.8.5"
[lints.rust.unexpected_cfgs]
level = "warn"
priority = 0
check-cfg = [
"cfg(httparse_simd)",
"cfg(httparse_simd_target_feature_avx2)",
"cfg(httparse_simd_target_feature_sse42)",
"cfg(httparse_simd_neon_intrinsics)",
]
[profile.bench]
opt-level = 3
lto = true
codegen-units = 1

201
vendor/httparse/LICENSE-APACHE vendored Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

20
vendor/httparse/LICENSE-MIT vendored Normal file
View File

@@ -0,0 +1,20 @@
Copyright (c) 2015-2025 Sean McArthur
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

43
vendor/httparse/README.md vendored Normal file
View File

@@ -0,0 +1,43 @@
# httparse
[![crates.io](https://img.shields.io/crates/v/httparse.svg)](https://crates.io/crates/httparse)
[![Released API docs](https://docs.rs/httparse/badge.svg)](https://docs.rs/httparse)
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE-MIT)
[![CI](https://github.com/seanmonstar/httparse/workflows/CI/badge.svg)](https://github.com/seanmonstar/httparse/actions?query=workflow%3ACI)
[![Discord chat][discord-badge]][discord-url]
A push parser for the HTTP 1.x protocol. Avoids allocations. No copy. **Fast.**
Works with `no_std`, simply disable the `std` Cargo feature.
[Changelog](https://github.com/seanmonstar/httparse/releases)
[discord-badge]: https://img.shields.io/discord/500028886025895936.svg?logo=discord
[discord-url]: https://discord.gg/kkwpueZ
## Usage
```rust
let mut headers = [httparse::EMPTY_HEADER; 64];
let mut req = httparse::Request::new(&mut headers);
let buf = b"GET /index.html HTTP/1.1\r\nHost";
assert!(req.parse(buf)?.is_partial());
// a partial request, so we try again once we have more data
let buf = b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n";
assert!(req.parse(buf)?.is_complete());
```
## License
Licensed under either of
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or https://apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or https://opensource.org/licenses/MIT)
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

242
vendor/httparse/benches/parse.rs vendored Normal file
View File

@@ -0,0 +1,242 @@
use std::time::Duration;
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput, BatchSize};
const REQ_SHORT: &[u8] = b"\
GET / HTTP/1.0\r\n\
Host: example.com\r\n\
Cookie: session=60; user_id=1\r\n\r\n";
const REQ: &[u8] = b"\
GET /wp-content/uploads/2010/03/hello-kitty-darth-vader-pink.jpg HTTP/1.1\r\n\
Host: www.kittyhell.com\r\n\
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; ja-JP-mac; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 Pathtraq/0.9\r\n\
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n\
Accept-Language: ja,en-us;q=0.7,en;q=0.3\r\n\
Accept-Encoding: gzip,deflate\r\n\
Accept-Charset: Shift_JIS,utf-8;q=0.7,*;q=0.7\r\n\
Keep-Alive: 115\r\n\
Connection: keep-alive\r\n\
Cookie: wp_ozh_wsa_visits=2; wp_ozh_wsa_visit_lasttime=xxxxxxxxxx; __utma=xxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.x; __utmz=xxxxxxxxx.xxxxxxxxxx.x.x.utmccn=(referral)|utmcsr=reader.livedoor.com|utmcct=/reader/|utmcmd=referral|padding=under256\r\n\r\n";
fn req(c: &mut Criterion) {
c.benchmark_group("req")
.throughput(Throughput::Bytes(REQ.len() as u64))
.bench_function("req", |b| b.iter_batched_ref(|| {
[httparse::Header {
name: "",
value: &[],
}; 16]
},|headers| {
let mut req = httparse::Request::new(headers);
assert_eq!(
black_box(req.parse(REQ).unwrap()),
httparse::Status::Complete(REQ.len())
);
}, BatchSize::SmallInput));
}
fn req_short(c: &mut Criterion) {
c.benchmark_group("req_short")
.throughput(Throughput::Bytes(REQ_SHORT.len() as u64))
.bench_function("req_short", |b| b.iter_batched_ref(|| {
[httparse::Header {
name: "",
value: &[],
}; 16]
},|headers| {
let mut req = httparse::Request::new(headers);
assert_eq!(
req.parse(black_box(REQ_SHORT)).unwrap(),
httparse::Status::Complete(REQ_SHORT.len())
);
}, BatchSize::SmallInput));
}
const RESP_SHORT: &[u8] = b"\
HTTP/1.0 200 OK\r\n\
Date: Wed, 21 Oct 2015 07:28:00 GMT\r\n\
Set-Cookie: session=60; user_id=1\r\n\r\n";
// These particular headers don't all make semantic sense for a response, but they're syntactically valid.
const RESP: &[u8] = b"\
HTTP/1.1 200 OK\r\n\
Date: Wed, 21 Oct 2015 07:28:00 GMT\r\n\
Host: www.kittyhell.com\r\n\
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; ja-JP-mac; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 Pathtraq/0.9\r\n\
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n\
Accept-Language: ja,en-us;q=0.7,en;q=0.3\r\n\
Accept-Encoding: gzip,deflate\r\n\
Accept-Charset: Shift_JIS,utf-8;q=0.7,*;q=0.7\r\n\
Keep-Alive: 115\r\n\
Connection: keep-alive\r\n\
Cookie: wp_ozh_wsa_visits=2; wp_ozh_wsa_visit_lasttime=xxxxxxxxxx; __utma=xxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.x; __utmz=xxxxxxxxx.xxxxxxxxxx.x.x.utmccn=(referral)|utmcsr=reader.livedoor.com|utmcct=/reader/|utmcmd=referral|padding=under256\r\n\r\n";
fn resp(c: &mut Criterion) {
c.benchmark_group("resp")
.throughput(Throughput::Bytes(RESP.len() as u64))
.bench_function("resp", |b| b.iter_batched_ref(|| {
[httparse::Header {
name: "",
value: &[],
}; 16]
}, |headers| {
let mut resp = httparse::Response::new(headers);
assert_eq!(
resp.parse(black_box(RESP)).unwrap(),
httparse::Status::Complete(RESP.len())
);
}, BatchSize::SmallInput));
}
fn resp_short(c: &mut Criterion) {
c.benchmark_group("resp_short")
.throughput(Throughput::Bytes(RESP_SHORT.len() as u64))
.bench_function("resp_short", |b| b.iter_batched_ref(|| {
[httparse::Header {
name: "",
value: &[],
}; 16]
},
|headers| {
let mut resp = httparse::Response::new(headers);
assert_eq!(
resp.parse(black_box(RESP_SHORT)).unwrap(),
httparse::Status::Complete(RESP_SHORT.len())
);
}, BatchSize::SmallInput));
}
fn uri(c: &mut Criterion) {
fn _uri(c: &mut Criterion, name: &str, input: &'static [u8]) {
c.benchmark_group("uri")
.throughput(Throughput::Bytes(input.len() as u64))
.bench_function(name, |b| b.iter(|| {
let mut b = httparse::_benchable::Bytes::new(black_box(input));
httparse::_benchable::parse_uri(&mut b).unwrap()
}));
}
const S: &[u8] = b" ";
const CHUNK64: &[u8] = b"/wp-content/uploads/2022/08/31/hello-kitty-darth-vader-pink.webp";
let chunk_4k = CHUNK64.repeat(64);
// 1b to 4096b
for p in 0..=12 {
let n = 1 << p;
_uri(c, &format!("uri_{:04}b", n), [chunk_4k[..n].to_vec(), S.into()].concat().leak());
}
}
fn header(c: &mut Criterion) {
fn _header(c: &mut Criterion, name: &str, input: &'static [u8]) {
c.benchmark_group("header")
.throughput(Throughput::Bytes(input.len() as u64))
.bench_function(name, |b| b.iter_batched_ref(|| [httparse::EMPTY_HEADER; 128],|headers| {
let status = httparse::parse_headers(black_box(input), headers).unwrap();
black_box(status.unwrap()).0
}, BatchSize::SmallInput));
}
const RN: &[u8] = b"\r\n";
const RNRN: &[u8] = b"\r\n\r\n";
const TINY_RN: &[u8] = b"a: b\r\n"; // minimal header line
const XFOOBAR: &[u8] = b"X-Foobar";
let xfoobar_4k = XFOOBAR.repeat(4096/XFOOBAR.len());
// header names 1b to 4096b
for p in 0..=12 {
let n = 1 << p;
let payload = [&xfoobar_4k[..n], b": b", RNRN].concat().leak();
_header(c, &format!("name_{:04}b", n), payload);
}
// header values 1b to 4096b
for p in 0..=12 {
let n = 1 << p;
let payload = [b"a: ", &xfoobar_4k[..n], RNRN].concat().leak();
_header(c, &format!("value_{:04}b", n), payload);
}
// 1 to 128
for p in 0..=7 {
let n = 1 << p;
_header(c, &format!("count_{:03}", n), [TINY_RN.repeat(n), RN.into()].concat().leak());
}
}
fn version(c: &mut Criterion) {
fn _version(c: &mut Criterion, name: &str, input: &'static [u8]) {
c.benchmark_group("version")
.throughput(Throughput::Bytes(input.len() as u64))
.bench_function(name, |b| b.iter(|| {
let mut b = httparse::_benchable::Bytes::new(black_box(input));
httparse::_benchable::parse_version(&mut b).unwrap()
}));
}
_version(c, "http10", b"HTTP/1.0\r\n");
_version(c, "http11", b"HTTP/1.1\r\n");
_version(c, "partial", b"HTTP/1.");
}
fn method(c: &mut Criterion) {
fn _method(c: &mut Criterion, name: &str, input: &[u8]) {
c.benchmark_group("method")
.throughput(Throughput::Bytes(input.len() as u64))
.bench_function(name, |b| b.iter(|| {
let mut b = httparse::_benchable::Bytes::new(black_box(input));
httparse::_benchable::parse_method(&mut b).unwrap()
}));
}
// Common methods should be fast-pathed
const COMMON_METHODS: &[&str] = &["GET", "HEAD", "POST", "PUT", "DELETE", "CONNECT", "OPTIONS", "TRACE", "PATCH"];
for method in COMMON_METHODS {
_method(c, &method.to_lowercase(), format!("{} / HTTP/1.1\r\n", method).as_bytes());
}
// Custom methods should be infrequent and thus not worth optimizing
_method(c, "custom", b"CUSTOM / HTTP/1.1\r\n");
_method(c, "w3!rd", b"w3!rd / HTTP/1.1\r\n");
}
fn many_requests(c: &mut Criterion) {
use rand::{rngs::StdRng, seq::SliceRandom, SeedableRng};
let mut requests = [
("GET", 500),
("POST", 300),
("OPTIONS", 100),
("HEAD", 50),
("w3!r`d", 20),
]
.iter()
.flat_map(|&(method, count)| std::iter::repeat(method).take(count))
.map(|method| format!("{method} / HTTP/1.1\r\n\r\n"))
.collect::<Vec<_>>();
SliceRandom::shuffle(&mut *requests, &mut StdRng::seed_from_u64(0));
let total_bytes: usize = requests.iter().map(String::len).sum();
c.benchmark_group("many_requests")
.throughput(Throughput::Bytes(total_bytes as u64))
.measurement_time(Duration::from_secs(1))
.sample_size(1000)
.bench_function("_", |b| {
b.iter(|| {
requests.iter().for_each(|req| {
let mut b = httparse::_benchable::Bytes::new(black_box(req.as_bytes()));
httparse::_benchable::parse_method(&mut b).unwrap();
});
})
});
}
const WARMUP: Duration = Duration::from_millis(100);
const MTIME: Duration = Duration::from_millis(100);
const SAMPLES: usize = 200;
criterion_group!{
name = benches;
config = Criterion::default().sample_size(SAMPLES).warm_up_time(WARMUP).measurement_time(MTIME);
targets = req, req_short, resp, resp_short, uri, header, version, method, many_requests
}
criterion_main!(benches);

133
vendor/httparse/build.rs vendored Normal file
View File

@@ -0,0 +1,133 @@
use std::env;
use std::ffi::OsString;
use std::process::Command;
fn main() {
// We check rustc version to enable features beyond MSRV, such as:
// - 1.59 => neon_intrinsics
let rustc = env::var_os("RUSTC").unwrap_or(OsString::from("rustc"));
let output = Command::new(rustc)
.arg("--version")
.output()
.expect("failed to check 'rustc --version'")
.stdout;
let raw_version = String::from_utf8(output)
.expect("rustc version output should be utf-8");
let version = match Version::parse(&raw_version) {
Ok(version) => version,
Err(err) => {
println!("cargo:warning=failed to parse `rustc --version`: {}", err);
return;
}
};
enable_new_features(version);
}
fn enable_new_features(version: Version) {
enable_simd(version);
}
fn enable_simd(version: Version) {
if env::var_os("CARGO_FEATURE_STD").is_none() {
println!("cargo:warning=building for no_std disables httparse SIMD");
return;
}
if env::var_os("CARGO_CFG_MIRI").is_some() {
println!("cargo:warning=building for Miri disables httparse SIMD");
return;
}
let env_disable = "CARGO_CFG_HTTPARSE_DISABLE_SIMD";
if var_is(env_disable, "1") {
println!("cargo:warning=detected {} environment variable, disabling SIMD", env_disable);
return;
}
// 1.59.0 is the first version to support neon_intrinsics
if version >= Version(1, 59, 0) {
println!("cargo:rustc-cfg=httparse_simd_neon_intrinsics");
}
println!("cargo:rustc-cfg=httparse_simd");
// cfg(target_feature) isn't stable yet, but CARGO_CFG_TARGET_FEATURE has
// a list... We aren't doing anything unsafe, since the is_x86_feature_detected
// macro still checks in the actual lib, BUT!
//
// By peeking at the list here, we can change up slightly how we do feature
// detection in the lib. If our features aren't in the feature list, we
// stick with a cached runtime detection strategy.
//
// But if the features *are* in the list, we benefit from removing our cache,
// since the compiler will eliminate several branches with its internal
// cfg(target_feature) usage.
let env_runtime_only = "CARGO_CFG_HTTPARSE_DISABLE_SIMD_COMPILETIME";
if var_is(env_runtime_only, "1") {
println!("cargo:warning=detected {} environment variable, using runtime SIMD detection only", env_runtime_only);
return;
}
let feature_list = match env::var_os("CARGO_CFG_TARGET_FEATURE") {
Some(var) => match var.into_string() {
Ok(s) => s,
Err(_) => {
println!("cargo:warning=CARGO_CFG_TARGET_FEATURE was not valid utf-8");
return;
},
},
None => {
println!("cargo:warning=CARGO_CFG_TARGET_FEATURE was not set");
return
},
};
let features = feature_list.split(',').map(|s| s.trim());
if features.clone().any(|f| f == "sse4.2") {
println!("cargo:rustc-cfg=httparse_simd_target_feature_sse42");
}
if features.clone().any(|f| f == "avx2") {
println!("cargo:rustc-cfg=httparse_simd_target_feature_avx2");
}
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
struct Version (u32, u32, u32);
impl Version {
fn parse(s: &str) -> Result<Version, String> {
if !s.starts_with("rustc ") {
return Err(format!("unrecognized version string: {}", s));
}
let s = s.trim_start_matches("rustc ");
let mut iter = s
.split('.')
.take(3)
.map(|s| match s.find(|c: char| !c.is_ascii_digit()) {
Some(end) => &s[..end],
None => s,
})
.map(|s| s.parse::<u32>().map_err(|e| e.to_string()));
if iter.clone().count() != 3 {
return Err(format!("not enough version parts: {:?}", s));
}
let major = iter.next().unwrap()?;
let minor = iter.next().unwrap()?;
let patch = iter.next().unwrap()?;
Ok(Version(major, minor, patch))
}
}
fn var_is(key: &str, val: &str) -> bool {
match env::var(key) {
Ok(v) => v == val,
Err(_) => false,
}
}

1
vendor/httparse/clippy.toml vendored Normal file
View File

@@ -0,0 +1 @@
msrv = "1.47"

199
vendor/httparse/src/iter.rs vendored Normal file
View File

@@ -0,0 +1,199 @@
use core::convert::TryFrom;
use core::convert::TryInto;
#[allow(missing_docs)]
pub struct Bytes<'a> {
start: *const u8,
end: *const u8,
/// INVARIANT: start <= cursor && cursor <= end
cursor: *const u8,
phantom: core::marker::PhantomData<&'a ()>,
}
#[allow(missing_docs)]
impl<'a> Bytes<'a> {
#[inline]
pub fn new(slice: &'a [u8]) -> Bytes<'a> {
let start = slice.as_ptr();
// SAFETY: obtain pointer to slice end; start points to slice start.
let end = unsafe { start.add(slice.len()) };
let cursor = start;
Bytes {
start,
end,
cursor,
phantom: core::marker::PhantomData,
}
}
#[inline]
pub fn pos(&self) -> usize {
self.cursor as usize - self.start as usize
}
#[inline]
pub fn peek(&self) -> Option<u8> {
if self.cursor < self.end {
// SAFETY: bounds checked
Some(unsafe { *self.cursor })
} else {
None
}
}
/// Peek at byte `n` ahead of cursor
///
/// # Safety
///
/// Caller must ensure that `n <= self.len()`, otherwise `self.cursor.add(n)` is UB.
/// That means there are at least `n-1` bytes between `self.cursor` and `self.end`
/// and `self.cursor.add(n)` is either `self.end` or points to a valid byte.
#[inline]
pub unsafe fn peek_ahead(&self, n: usize) -> Option<u8> {
debug_assert!(n <= self.len());
// SAFETY: by preconditions
let p = unsafe { self.cursor.add(n) };
if p < self.end {
// SAFETY: by preconditions, if this is not `self.end`,
// then it is safe to dereference
Some(unsafe { *p })
} else {
None
}
}
#[inline]
pub fn peek_n<'b: 'a, U: TryFrom<&'a [u8]>>(&'b self, n: usize) -> Option<U> {
// TODO: once we bump MSRC, use const generics to allow only [u8; N] reads
// TODO: drop `n` arg in favour of const
// let n = core::mem::size_of::<U>();
self.as_ref().get(..n)?.try_into().ok()
}
/// Advance by 1, equivalent to calling `advance(1)`.
///
/// # Safety
///
/// Caller must ensure that Bytes hasn't been advanced/bumped by more than [`Bytes::len()`].
#[inline]
pub unsafe fn bump(&mut self) {
self.advance(1)
}
/// Advance cursor by `n`
///
/// # Safety
///
/// Caller must ensure that Bytes hasn't been advanced/bumped by more than [`Bytes::len()`].
#[inline]
pub unsafe fn advance(&mut self, n: usize) {
self.cursor = self.cursor.add(n);
debug_assert!(self.cursor <= self.end, "overflow");
}
#[inline]
pub fn len(&self) -> usize {
self.end as usize - self.cursor as usize
}
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
#[inline]
pub fn slice(&mut self) -> &'a [u8] {
// SAFETY: not moving position at all, so it's safe
let slice = unsafe { slice_from_ptr_range(self.start, self.cursor) };
self.commit();
slice
}
// TODO: this is an anti-pattern, should be removed
/// Deprecated. Do not use!
/// # Safety
///
/// Caller must ensure that `skip` is at most the number of advances (i.e., `bytes.advance(3)`
/// implies a skip of at most 3).
#[inline]
pub unsafe fn slice_skip(&mut self, skip: usize) -> &'a [u8] {
debug_assert!(skip <= self.cursor.offset_from(self.start) as usize);
let head = slice_from_ptr_range(self.start, self.cursor.sub(skip));
self.commit();
head
}
#[inline]
pub fn commit(&mut self) {
self.start = self.cursor
}
/// # Safety
///
/// see [`Bytes::advance`] safety comment.
#[inline]
pub unsafe fn advance_and_commit(&mut self, n: usize) {
self.advance(n);
self.commit();
}
#[inline]
pub fn as_ptr(&self) -> *const u8 {
self.cursor
}
#[inline]
pub fn start(&self) -> *const u8 {
self.start
}
#[inline]
pub fn end(&self) -> *const u8 {
self.end
}
/// # Safety
///
/// Must ensure invariant `bytes.start() <= ptr && ptr <= bytes.end()`.
#[inline]
pub unsafe fn set_cursor(&mut self, ptr: *const u8) {
debug_assert!(ptr >= self.start);
debug_assert!(ptr <= self.end);
self.cursor = ptr;
}
}
impl AsRef<[u8]> for Bytes<'_> {
#[inline]
fn as_ref(&self) -> &[u8] {
// SAFETY: not moving position at all, so it's safe
unsafe { slice_from_ptr_range(self.cursor, self.end) }
}
}
/// # Safety
///
/// Must ensure start and end point to the same memory object to uphold memory safety.
#[inline]
unsafe fn slice_from_ptr_range<'a>(start: *const u8, end: *const u8) -> &'a [u8] {
debug_assert!(start <= end);
core::slice::from_raw_parts(start, end as usize - start as usize)
}
impl Iterator for Bytes<'_> {
type Item = u8;
#[inline]
fn next(&mut self) -> Option<u8> {
if self.cursor < self.end {
// SAFETY: bounds checked dereference
unsafe {
let b = *self.cursor;
self.bump();
Some(b)
}
} else {
None
}
}
}

2798
vendor/httparse/src/lib.rs vendored Normal file

File diff suppressed because it is too large Load Diff

68
vendor/httparse/src/macros.rs vendored Normal file
View File

@@ -0,0 +1,68 @@
//! Utility macros
macro_rules! next {
($bytes:ident) => ({
match $bytes.next() {
Some(b) => b,
None => return Ok(Status::Partial)
}
})
}
macro_rules! expect {
($bytes:ident.next() == $pat:pat => $ret:expr) => {
expect!(next!($bytes) => $pat |? $ret)
};
($e:expr => $pat:pat |? $ret:expr) => {
match $e {
v@$pat => v,
_ => return $ret
}
};
}
macro_rules! complete {
($e:expr) => {
match $e? {
Status::Complete(v) => v,
Status::Partial => return Ok(Status::Partial)
}
}
}
macro_rules! byte_map {
($($p:pat)|+) => {{
const fn make_map() -> [bool; 256] {
let mut ret = [false; 256];
let mut i = 0;
while i < 256 {
ret[i] = matches!(i as u8, $($p)|+);
i += 1;
}
ret
}
make_map()
}}
}
macro_rules! space {
($bytes:ident or $err:expr) => ({
expect!($bytes.next() == b' ' => Err($err));
$bytes.slice();
})
}
macro_rules! newline {
($bytes:ident) => ({
match next!($bytes) {
b'\r' => {
expect!($bytes.next() == b'\n' => Err(Error::NewLine));
$bytes.slice();
},
b'\n' => {
$bytes.slice();
},
_ => return Err(Error::NewLine)
}
})
}

206
vendor/httparse/src/simd/avx2.rs vendored Normal file
View File

@@ -0,0 +1,206 @@
use crate::iter::Bytes;
#[inline]
#[target_feature(enable = "avx2")]
pub unsafe fn match_uri_vectored(bytes: &mut Bytes) {
while bytes.as_ref().len() >= 32 {
let advance = match_url_char_32_avx(bytes.as_ref());
bytes.advance(advance);
if advance != 32 {
return;
}
}
// NOTE: use SWAR for <32B, more efficient than falling back to SSE4.2
super::swar::match_uri_vectored(bytes)
}
#[inline(always)]
#[allow(non_snake_case, overflowing_literals)]
#[allow(unused)]
unsafe fn match_url_char_32_avx(buf: &[u8]) -> usize {
// NOTE: This check might be not necessary since this function is only used in
// `match_uri_vectored` where buffer overflow is taken care of.
debug_assert!(buf.len() >= 32);
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;
// pointer to buffer
let ptr = buf.as_ptr();
// %x21-%x7e %x80-%xff
//
// Character ranges allowed by this function, can also be interpreted as:
// 33 =< (x != 127) =< 255
//
// Create a vector full of DEL (0x7f) characters.
let DEL: __m256i = _mm256_set1_epi8(0x7f);
// Create a vector full of exclamation mark (!) (0x21) characters.
// Used as lower threshold, characters in URLs cannot be smaller than this.
let LOW: __m256i = _mm256_set1_epi8(0x21);
// Load a chunk of 32 bytes from `ptr` as a vector.
// We can check 32 bytes in parallel at most with AVX2 since
// YMM registers can only have 256 bits most.
let dat = _mm256_lddqu_si256(ptr as *const _);
// unsigned comparison dat >= LOW
//
// `_mm256_max_epu8` creates a new vector by comparing vectors `dat` and `LOW`
// and picks the max. values from each for all indices.
// So if a byte in `dat` is <= 32, it'll be represented as 33
// which is the smallest valid character.
//
// Then, we compare the new vector with `dat` for equality.
//
// `_mm256_cmpeq_epi8` returns a new vector where;
// * matching bytes are set to 0xFF (all bits set),
// * nonmatching bytes are set to 0 (no bits set).
let low = _mm256_cmpeq_epi8(_mm256_max_epu8(dat, LOW), dat);
// Similar to what we did before, but now invalid characters are set to 0xFF.
let del = _mm256_cmpeq_epi8(dat, DEL);
// We glue the both comparisons via `_mm256_andnot_si256`.
//
// Since the representation of truthiness differ in these comparisons,
// we are in need of bitwise NOT to convert valid characters of `del`.
let bit = _mm256_andnot_si256(del, low);
// This creates a bitmask from the most significant bit of each byte.
// Simply, we're converting a vector value to scalar value here.
let res = _mm256_movemask_epi8(bit) as u32;
// Count trailing zeros to find the first encountered invalid character.
// Bitwise NOT is required once again to flip truthiness.
// TODO: use .trailing_ones() once MSRV >= 1.46
(!res).trailing_zeros() as usize
}
#[target_feature(enable = "avx2")]
pub unsafe fn match_header_value_vectored(bytes: &mut Bytes) {
while bytes.as_ref().len() >= 32 {
let advance = match_header_value_char_32_avx(bytes.as_ref());
bytes.advance(advance);
if advance != 32 {
return;
}
}
// NOTE: use SWAR for <32B, more efficient than falling back to SSE4.2
super::swar::match_header_value_vectored(bytes)
}
#[inline(always)]
#[allow(non_snake_case)]
#[allow(unused)]
unsafe fn match_header_value_char_32_avx(buf: &[u8]) -> usize {
debug_assert!(buf.len() >= 32);
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;
let ptr = buf.as_ptr();
// %x09 %x20-%x7e %x80-%xff
// Create a vector full of horizontal tab (\t) (0x09) characters.
let TAB: __m256i = _mm256_set1_epi8(0x09);
// Create a vector full of DEL (0x7f) characters.
let DEL: __m256i = _mm256_set1_epi8(0x7f);
// Create a vector full of space (0x20) characters.
let LOW: __m256i = _mm256_set1_epi8(0x20);
// Load a chunk of 32 bytes from `ptr` as a vector.
let dat = _mm256_lddqu_si256(ptr as *const _);
// unsigned comparison dat >= LOW
//
// Same as what we do in `match_url_char_32_avx`.
// This time the lower threshold is set to space character though.
let low = _mm256_cmpeq_epi8(_mm256_max_epu8(dat, LOW), dat);
// Check if `dat` includes `TAB` characters.
let tab = _mm256_cmpeq_epi8(dat, TAB);
// Check if `dat` includes `DEL` characters.
let del = _mm256_cmpeq_epi8(dat, DEL);
// Combine all comparisons together, notice that we're also using OR
// to connect `low` and `tab` but flip bits of `del`.
//
// In the end, this is simply:
// ~del & (low | tab)
let bit = _mm256_andnot_si256(del, _mm256_or_si256(low, tab));
// This creates a bitmask from the most significant bit of each byte.
// Creates a scalar value from vector value.
let res = _mm256_movemask_epi8(bit) as u32;
// Count trailing zeros to find the first encountered invalid character.
// Bitwise NOT is required once again to flip truthiness.
// TODO: use .trailing_ones() once MSRV >= 1.46
(!res).trailing_zeros() as usize
}
#[test]
fn avx2_code_matches_uri_chars_table() {
if !is_x86_feature_detected!("avx2") {
return;
}
#[allow(clippy::undocumented_unsafe_blocks)]
unsafe {
assert!(byte_is_allowed(b'_', match_uri_vectored));
for (b, allowed) in crate::URI_MAP.iter().cloned().enumerate() {
assert_eq!(
byte_is_allowed(b as u8, match_uri_vectored), allowed,
"byte_is_allowed({:?}) should be {:?}", b, allowed,
);
}
}
}
#[test]
fn avx2_code_matches_header_value_chars_table() {
if !is_x86_feature_detected!("avx2") {
return;
}
#[allow(clippy::undocumented_unsafe_blocks)]
unsafe {
assert!(byte_is_allowed(b'_', match_header_value_vectored));
for (b, allowed) in crate::HEADER_VALUE_MAP.iter().cloned().enumerate() {
assert_eq!(
byte_is_allowed(b as u8, match_header_value_vectored), allowed,
"byte_is_allowed({:?}) should be {:?}", b, allowed,
);
}
}
}
#[cfg(test)]
unsafe fn byte_is_allowed(byte: u8, f: unsafe fn(bytes: &mut Bytes<'_>)) -> bool {
let slice = [
b'_', b'_', b'_', b'_',
b'_', b'_', b'_', b'_',
b'_', b'_', b'_', b'_',
b'_', b'_', b'_', b'_',
b'_', b'_', b'_', b'_',
b'_', b'_', b'_', b'_',
b'_', b'_', byte, b'_',
b'_', b'_', b'_', b'_',
];
let mut bytes = Bytes::new(&slice);
f(&mut bytes);
match bytes.pos() {
32 => true,
26 => false,
_ => unreachable!(),
}
}

153
vendor/httparse/src/simd/mod.rs vendored Normal file
View File

@@ -0,0 +1,153 @@
mod swar;
#[cfg(not(all(
httparse_simd,
any(
target_arch = "x86",
target_arch = "x86_64",
all(
target_arch = "aarch64",
httparse_simd_neon_intrinsics,
)
),
)))]
pub use self::swar::*;
#[cfg(all(
httparse_simd,
not(httparse_simd_target_feature_avx2),
any(
target_arch = "x86",
target_arch = "x86_64",
),
))]
mod sse42;
#[cfg(all(
httparse_simd,
any(
httparse_simd_target_feature_avx2,
not(httparse_simd_target_feature_sse42),
),
any(
target_arch = "x86",
target_arch = "x86_64",
),
))]
mod avx2;
#[cfg(all(
httparse_simd,
not(any(
httparse_simd_target_feature_sse42,
httparse_simd_target_feature_avx2,
)),
any(
target_arch = "x86",
target_arch = "x86_64",
),
))]
mod runtime;
#[cfg(all(
httparse_simd,
not(any(
httparse_simd_target_feature_sse42,
httparse_simd_target_feature_avx2,
)),
any(
target_arch = "x86",
target_arch = "x86_64",
),
))]
pub use self::runtime::*;
#[cfg(all(
httparse_simd,
httparse_simd_target_feature_sse42,
not(httparse_simd_target_feature_avx2),
any(
target_arch = "x86",
target_arch = "x86_64",
),
))]
mod sse42_compile_time {
#[inline(always)]
pub fn match_header_name_vectored(b: &mut crate::iter::Bytes<'_>) {
super::swar::match_header_name_vectored(b);
}
#[inline(always)]
pub fn match_uri_vectored(b: &mut crate::iter::Bytes<'_>) {
// SAFETY: calls are guarded by a compile time feature check
unsafe { crate::simd::sse42::match_uri_vectored(b) }
}
#[inline(always)]
pub fn match_header_value_vectored(b: &mut crate::iter::Bytes<'_>) {
// SAFETY: calls are guarded by a compile time feature check
unsafe { crate::simd::sse42::match_header_value_vectored(b) }
}
}
#[cfg(all(
httparse_simd,
httparse_simd_target_feature_sse42,
not(httparse_simd_target_feature_avx2),
any(
target_arch = "x86",
target_arch = "x86_64",
),
))]
pub use self::sse42_compile_time::*;
#[cfg(all(
httparse_simd,
httparse_simd_target_feature_avx2,
any(
target_arch = "x86",
target_arch = "x86_64",
),
))]
mod avx2_compile_time {
#[inline(always)]
pub fn match_header_name_vectored(b: &mut crate::iter::Bytes<'_>) {
super::swar::match_header_name_vectored(b);
}
#[inline(always)]
pub fn match_uri_vectored(b: &mut crate::iter::Bytes<'_>) {
// SAFETY: calls are guarded by a compile time feature check
unsafe { crate::simd::avx2::match_uri_vectored(b) }
}
#[inline(always)]
pub fn match_header_value_vectored(b: &mut crate::iter::Bytes<'_>) {
// SAFETY: calls are guarded by a compile time feature check
unsafe { crate::simd::avx2::match_header_value_vectored(b) }
}
}
#[cfg(all(
httparse_simd,
httparse_simd_target_feature_avx2,
any(
target_arch = "x86",
target_arch = "x86_64",
),
))]
pub use self::avx2_compile_time::*;
#[cfg(all(
httparse_simd,
target_arch = "aarch64",
httparse_simd_neon_intrinsics,
))]
mod neon;
#[cfg(all(
httparse_simd,
target_arch = "aarch64",
httparse_simd_neon_intrinsics,
))]
pub use self::neon::*;

258
vendor/httparse/src/simd/neon.rs vendored Normal file
View File

@@ -0,0 +1,258 @@
use crate::iter::Bytes;
use core::arch::aarch64::*;
#[inline]
pub fn match_header_name_vectored(bytes: &mut Bytes) {
while bytes.as_ref().len() >= 16 {
// SAFETY: ensured that there are at least 16 bytes remaining
unsafe {
let advance = match_header_name_char_16_neon(bytes.as_ref().as_ptr());
bytes.advance(advance);
if advance != 16 {
return;
}
}
}
super::swar::match_header_name_vectored(bytes);
}
#[inline]
pub fn match_header_value_vectored(bytes: &mut Bytes) {
while bytes.as_ref().len() >= 16 {
// SAFETY: ensured that there are at least 16 bytes remaining
unsafe {
let advance = match_header_value_char_16_neon(bytes.as_ref().as_ptr());
bytes.advance(advance);
if advance != 16 {
return;
}
}
}
super::swar::match_header_value_vectored(bytes);
}
#[inline]
pub fn match_uri_vectored(bytes: &mut Bytes) {
while bytes.as_ref().len() >= 16 {
// SAFETY: ensured that there are at least 16 bytes remaining
unsafe {
let advance = match_url_char_16_neon(bytes.as_ref().as_ptr());
bytes.advance(advance);
if advance != 16 {
return;
}
}
}
super::swar::match_uri_vectored(bytes);
}
const fn bit_set(x: u8) -> bool {
// Validates if a byte is a valid header name character
// https://tools.ietf.org/html/rfc7230#section-3.2.6
matches!(x, b'0'..=b'9' | b'a'..=b'z' | b'A'..=b'Z' | b'!' | b'#' | b'$' | b'%' | b'&' | b'\'' | b'*' | b'+' | b'-' | b'.' | b'^' | b'_' | b'`' | b'|' | b'~')
}
// A 256-bit bitmap, split into two halves
// lower half contains bits whose higher nibble is <= 7
// higher half contains bits whose higher nibble is >= 8
const fn build_bitmap() -> ([u8; 16], [u8; 16]) {
let mut bitmap_0_7 = [0u8; 16]; // 0x00..0x7F
let mut bitmap_8_15 = [0u8; 16]; // 0x80..0xFF
let mut i = 0;
while i < 256 {
if bit_set(i as u8) {
// Nibbles
let (lo, hi) = (i & 0x0F, i >> 4);
if i < 128 {
bitmap_0_7[lo] |= 1 << hi;
} else {
bitmap_8_15[lo] |= 1 << hi;
}
}
i += 1;
}
(bitmap_0_7, bitmap_8_15)
}
const BITMAPS: ([u8; 16], [u8; 16]) = build_bitmap();
// NOTE: adapted from 256-bit version, with upper 128-bit ops commented out
#[inline]
unsafe fn match_header_name_char_16_neon(ptr: *const u8) -> usize {
let bitmaps = BITMAPS;
// NOTE: ideally compile-time constants
let (bitmap_0_7, _bitmap_8_15) = bitmaps;
let bitmap_0_7 = vld1q_u8(bitmap_0_7.as_ptr());
// let bitmap_8_15 = vld1q_u8(bitmap_8_15.as_ptr());
// Initialize the bitmask_lookup.
const BITMASK_LOOKUP_DATA: [u8; 16] =
[1, 2, 4, 8, 16, 32, 64, 128, 1, 2, 4, 8, 16, 32, 64, 128];
let bitmask_lookup = vld1q_u8(BITMASK_LOOKUP_DATA.as_ptr());
// Load 16 input bytes.
let input = vld1q_u8(ptr);
// Extract indices for row_0_7.
let indices_0_7 = vandq_u8(input, vdupq_n_u8(0x8F)); // 0b1000_1111;
// Extract indices for row_8_15.
// let msb = vandq_u8(input, vdupq_n_u8(0x80));
// let indices_8_15 = veorq_u8(indices_0_7, msb);
// Fetch row_0_7 and row_8_15.
let row_0_7 = vqtbl1q_u8(bitmap_0_7, indices_0_7);
// let row_8_15 = vqtbl1q_u8(bitmap_8_15, indices_8_15);
// Calculate a bitmask, i.e. (1 << hi_nibble % 8).
let bitmask = vqtbl1q_u8(bitmask_lookup, vshrq_n_u8(input, 4));
// Choose rows halves depending on higher nibbles.
// let bitsets = vorrq_u8(row_0_7, row_8_15);
let bitsets = row_0_7;
// Finally check which bytes belong to the set.
let tmp = vandq_u8(bitsets, bitmask);
let result = vceqq_u8(tmp, bitmask);
offsetz(result) as usize
}
#[inline]
unsafe fn match_url_char_16_neon(ptr: *const u8) -> usize {
let input = vld1q_u8(ptr);
// Check that b'!' <= and b != 127
let result = vcleq_u8(vdupq_n_u8(b'!'), input);
// Disallow del
let del = vceqq_u8(input, vdupq_n_u8(0x7F));
let result = vbicq_u8(result, del);
offsetz(result) as usize
}
#[inline]
unsafe fn match_header_value_char_16_neon(ptr: *const u8) -> usize {
let input = vld1q_u8(ptr);
// Check that b' ' <= and b != 127 or b == 9
let result = vcleq_u8(vdupq_n_u8(b' '), input);
// Allow tab
let tab = vceqq_u8(input, vdupq_n_u8(0x09));
let result = vorrq_u8(result, tab);
// Disallow del
let del = vceqq_u8(input, vdupq_n_u8(0x7F));
let result = vbicq_u8(result, del);
offsetz(result) as usize
}
#[inline]
unsafe fn offsetz(x: uint8x16_t) -> u32 {
// NOT the vector since it's faster to operate with zeros instead
offsetnz(vmvnq_u8(x))
}
#[inline]
unsafe fn offsetnz(x: uint8x16_t) -> u32 {
// Extract two u64
let x = vreinterpretq_u64_u8(x);
// Extract to general purpose registers to perform clz
let low: u64 = vgetq_lane_u64::<0>(x);
let high: u64 = vgetq_lane_u64::<1>(x);
#[inline]
fn clz(x: u64) -> u32 {
// perf: rust will unroll this loop
// and it's much faster than rbit + clz so voila
for (i, b) in x.to_ne_bytes().iter().copied().enumerate() {
if b != 0 {
return i as u32;
}
}
8 // Technically not reachable since zero-guarded
}
if low != 0 {
clz(low)
} else if high != 0 {
return 8 + clz(high);
} else {
return 16;
}
}
#[test]
fn neon_code_matches_uri_chars_table() {
#[allow(clippy::undocumented_unsafe_blocks)]
unsafe {
assert!(byte_is_allowed(b'_', match_uri_vectored));
for (b, allowed) in crate::URI_MAP.iter().cloned().enumerate() {
assert_eq!(
byte_is_allowed(b as u8, match_uri_vectored),
allowed,
"byte_is_allowed({:?}) should be {:?}",
b,
allowed,
);
}
}
}
#[test]
fn neon_code_matches_header_value_chars_table() {
#[allow(clippy::undocumented_unsafe_blocks)]
unsafe {
assert!(byte_is_allowed(b'_', match_header_value_vectored));
for (b, allowed) in crate::HEADER_VALUE_MAP.iter().cloned().enumerate() {
assert_eq!(
byte_is_allowed(b as u8, match_header_value_vectored),
allowed,
"byte_is_allowed({:?}) should be {:?}",
b,
allowed,
);
}
}
}
#[test]
fn neon_code_matches_header_name_chars_table() {
#[allow(clippy::undocumented_unsafe_blocks)]
unsafe {
assert!(byte_is_allowed(b'_', match_header_name_vectored));
for (b, allowed) in crate::TOKEN_MAP.iter().cloned().enumerate() {
assert_eq!(
byte_is_allowed(b as u8, match_header_name_vectored),
allowed,
"byte_is_allowed({:?}) should be {:?}",
b,
allowed,
);
}
}
}
#[cfg(test)]
unsafe fn byte_is_allowed(byte: u8, f: unsafe fn(bytes: &mut Bytes<'_>)) -> bool {
let mut slice = [b'_'; 16];
slice[10] = byte;
let mut bytes = Bytes::new(&slice);
f(&mut bytes);
match bytes.pos() {
16 => true,
10 => false,
x => panic!("unexpected pos: {}", x),
}
}

57
vendor/httparse/src/simd/runtime.rs vendored Normal file
View File

@@ -0,0 +1,57 @@
use std::sync::atomic::{AtomicU8, Ordering};
use crate::iter::Bytes;
use super::avx2;
use super::sse42;
const AVX2: u8 = 1;
const SSE42: u8 = 2;
const NOP: u8 = 3;
fn detect_runtime_feature() -> u8 {
if is_x86_feature_detected!("avx2") {
AVX2
} else if is_x86_feature_detected!("sse4.2") {
SSE42
} else {
NOP
}
}
static RUNTIME_FEATURE: AtomicU8 = AtomicU8::new(0);
#[inline]
fn get_runtime_feature() -> u8 {
let mut feature = RUNTIME_FEATURE.load(Ordering::Relaxed);
if feature == 0 {
feature = detect_runtime_feature();
RUNTIME_FEATURE.store(feature, Ordering::Relaxed);
}
feature
}
pub fn match_header_name_vectored(bytes: &mut Bytes) {
super::swar::match_header_name_vectored(bytes);
}
pub fn match_uri_vectored(bytes: &mut Bytes) {
// SAFETY: calls are guarded by a feature check
unsafe {
match get_runtime_feature() {
AVX2 => avx2::match_uri_vectored(bytes),
SSE42 => sse42::match_uri_vectored(bytes),
_ /* NOP */ => super::swar::match_uri_vectored(bytes),
}
}
}
pub fn match_header_value_vectored(bytes: &mut Bytes) {
// SAFETY: calls are guarded by a feature check
unsafe {
match get_runtime_feature() {
AVX2 => avx2::match_header_value_vectored(bytes),
SSE42 => sse42::match_header_value_vectored(bytes),
_ /* NOP */ => super::swar::match_header_value_vectored(bytes),
}
}
}

142
vendor/httparse/src/simd/sse42.rs vendored Normal file
View File

@@ -0,0 +1,142 @@
use crate::iter::Bytes;
#[target_feature(enable = "sse4.2")]
pub unsafe fn match_uri_vectored(bytes: &mut Bytes) {
while bytes.as_ref().len() >= 16 {
let advance = match_url_char_16_sse(bytes.as_ref());
bytes.advance(advance);
if advance != 16 {
return;
}
}
super::swar::match_uri_vectored(bytes);
}
#[inline(always)]
#[allow(non_snake_case)]
unsafe fn match_url_char_16_sse(buf: &[u8]) -> usize {
debug_assert!(buf.len() >= 16);
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;
let ptr = buf.as_ptr();
// %x21-%x7e %x80-%xff
let DEL: __m128i = _mm_set1_epi8(0x7f);
let LOW: __m128i = _mm_set1_epi8(0x21);
let dat = _mm_lddqu_si128(ptr as *const _);
// unsigned comparison dat >= LOW
let low = _mm_cmpeq_epi8(_mm_max_epu8(dat, LOW), dat);
let del = _mm_cmpeq_epi8(dat, DEL);
let bit = _mm_andnot_si128(del, low);
let res = _mm_movemask_epi8(bit) as u16;
// TODO: use .trailing_ones() once MSRV >= 1.46
(!res).trailing_zeros() as usize
}
#[target_feature(enable = "sse4.2")]
pub unsafe fn match_header_value_vectored(bytes: &mut Bytes) {
while bytes.as_ref().len() >= 16 {
let advance = match_header_value_char_16_sse(bytes.as_ref());
bytes.advance(advance);
if advance != 16 {
return;
}
}
super::swar::match_header_value_vectored(bytes);
}
#[inline(always)]
#[allow(non_snake_case)]
unsafe fn match_header_value_char_16_sse(buf: &[u8]) -> usize {
debug_assert!(buf.len() >= 16);
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;
let ptr = buf.as_ptr();
// %x09 %x20-%x7e %x80-%xff
let TAB: __m128i = _mm_set1_epi8(0x09);
let DEL: __m128i = _mm_set1_epi8(0x7f);
let LOW: __m128i = _mm_set1_epi8(0x20);
let dat = _mm_lddqu_si128(ptr as *const _);
// unsigned comparison dat >= LOW
let low = _mm_cmpeq_epi8(_mm_max_epu8(dat, LOW), dat);
let tab = _mm_cmpeq_epi8(dat, TAB);
let del = _mm_cmpeq_epi8(dat, DEL);
let bit = _mm_andnot_si128(del, _mm_or_si128(low, tab));
let res = _mm_movemask_epi8(bit) as u16;
// TODO: use .trailing_ones() once MSRV >= 1.46
(!res).trailing_zeros() as usize
}
#[test]
fn sse_code_matches_uri_chars_table() {
if !is_x86_feature_detected!("sse4.2") {
return;
}
#[allow(clippy::undocumented_unsafe_blocks)]
unsafe {
assert!(byte_is_allowed(b'_', match_uri_vectored));
for (b, allowed) in crate::URI_MAP.iter().cloned().enumerate() {
assert_eq!(
byte_is_allowed(b as u8, match_uri_vectored), allowed,
"byte_is_allowed({:?}) should be {:?}", b, allowed,
);
}
}
}
#[test]
fn sse_code_matches_header_value_chars_table() {
if !is_x86_feature_detected!("sse4.2") {
return;
}
#[allow(clippy::undocumented_unsafe_blocks)]
unsafe {
assert!(byte_is_allowed(b'_', match_header_value_vectored));
for (b, allowed) in crate::HEADER_VALUE_MAP.iter().cloned().enumerate() {
assert_eq!(
byte_is_allowed(b as u8, match_header_value_vectored), allowed,
"byte_is_allowed({:?}) should be {:?}", b, allowed,
);
}
}
}
#[allow(clippy::missing_safety_doc)]
#[cfg(test)]
unsafe fn byte_is_allowed(byte: u8, f: unsafe fn(bytes: &mut Bytes<'_>)) -> bool {
let slice = [
b'_', b'_', b'_', b'_',
b'_', b'_', b'_', b'_',
b'_', b'_', byte, b'_',
b'_', b'_', b'_', b'_',
];
let mut bytes = Bytes::new(&slice);
f(&mut bytes);
match bytes.pos() {
16 => true,
10 => false,
_ => unreachable!(),
}
}

235
vendor/httparse/src/simd/swar.rs vendored Normal file
View File

@@ -0,0 +1,235 @@
/// SWAR: SIMD Within A Register
/// SIMD validator backend that validates register-sized chunks of data at a time.
use crate::{is_header_name_token, is_header_value_token, is_uri_token, Bytes};
// Adapt block-size to match native register size, i.e: 32bit => 4, 64bit => 8
const BLOCK_SIZE: usize = core::mem::size_of::<usize>();
type ByteBlock = [u8; BLOCK_SIZE];
#[inline]
pub fn match_uri_vectored(bytes: &mut Bytes) {
loop {
if let Some(bytes8) = bytes.peek_n::<ByteBlock>(BLOCK_SIZE) {
let n = match_uri_char_8_swar(bytes8);
// SAFETY: using peek_n to retrieve the bytes ensures that there are at least n more bytes
// in `bytes`, so calling `advance(n)` is safe.
unsafe {
bytes.advance(n);
}
if n == BLOCK_SIZE {
continue;
}
}
if let Some(b) = bytes.peek() {
if is_uri_token(b) {
// SAFETY: using peek to retrieve the byte ensures that there is at least 1 more byte
// in bytes, so calling advance is safe.
unsafe {
bytes.advance(1);
}
continue;
}
}
break;
}
}
#[inline]
pub fn match_header_value_vectored(bytes: &mut Bytes) {
loop {
if let Some(bytes8) = bytes.peek_n::<ByteBlock>(BLOCK_SIZE) {
let n = match_header_value_char_8_swar(bytes8);
// SAFETY: using peek_n to retrieve the bytes ensures that there are at least n more bytes
// in `bytes`, so calling `advance(n)` is safe.
unsafe {
bytes.advance(n);
}
if n == BLOCK_SIZE {
continue;
}
}
if let Some(b) = bytes.peek() {
if is_header_value_token(b) {
// SAFETY: using peek to retrieve the byte ensures that there is at least 1 more byte
// in bytes, so calling advance is safe.
unsafe {
bytes.advance(1);
}
continue;
}
}
break;
}
}
#[inline]
pub fn match_header_name_vectored(bytes: &mut Bytes) {
while let Some(block) = bytes.peek_n::<ByteBlock>(BLOCK_SIZE) {
let n = match_block(is_header_name_token, block);
// SAFETY: using peek_n to retrieve the bytes ensures that there are at least n more bytes
// in `bytes`, so calling `advance(n)` is safe.
unsafe {
bytes.advance(n);
}
if n != BLOCK_SIZE {
return;
}
}
// SAFETY: match_tail processes at most the remaining data in `bytes`. advances `bytes` to the
// end, but no further.
unsafe { bytes.advance(match_tail(is_header_name_token, bytes.as_ref())) };
}
// Matches "tail", i.e: when we have <BLOCK_SIZE bytes in the buffer, should be uncommon
#[cold]
#[inline]
fn match_tail(f: impl Fn(u8) -> bool, bytes: &[u8]) -> usize {
for (i, &b) in bytes.iter().enumerate() {
if !f(b) {
return i;
}
}
bytes.len()
}
// Naive fallback block matcher
#[inline(always)]
fn match_block(f: impl Fn(u8) -> bool, block: ByteBlock) -> usize {
for (i, &b) in block.iter().enumerate() {
if !f(b) {
return i;
}
}
BLOCK_SIZE
}
// A const alternative to u64::from_ne_bytes to avoid bumping MSRV (1.36 => 1.44)
// creates a u64 whose bytes are each equal to b
const fn uniform_block(b: u8) -> usize {
(b as u64 * 0x01_01_01_01_01_01_01_01 /* [1_u8; 8] */) as usize
}
// A byte-wise range-check on an entire word/block,
// ensuring all bytes in the word satisfy `33 <= (x != 127) <= 255`
#[inline]
fn match_uri_char_8_swar(block: ByteBlock) -> usize {
// 33 <= (x != 127) <= 255
const M: u8 = 0x21;
// uniform block full of exclamation mark (!) (33).
const BM: usize = uniform_block(M);
// uniform block full of 1.
const ONE: usize = uniform_block(0x01);
// uniform block full of DEL (127).
const DEL: usize = uniform_block(0x7f);
// uniform block full of 128.
const M128: usize = uniform_block(128);
let x = usize::from_ne_bytes(block); // Really just a transmute
let lt = x.wrapping_sub(BM) & !x; // <= m
let xor_del = x ^ DEL;
let eq_del = xor_del.wrapping_sub(ONE) & !xor_del; // == DEL
offsetnz((lt | eq_del) & M128)
}
// A byte-wise range-check on an entire word/block,
// ensuring all bytes in the word satisfy `32 <= (x != 127) <= 255`
#[inline]
fn match_header_value_char_8_swar(block: ByteBlock) -> usize {
// 32 <= (x != 127) <= 255
const M: u8 = 0x20;
// uniform block full of exclamation mark (!) (33).
const BM: usize = uniform_block(M);
// uniform block full of 1.
const ONE: usize = uniform_block(0x01);
// uniform block full of DEL (127).
const DEL: usize = uniform_block(0x7f);
// uniform block full of 128.
const M128: usize = uniform_block(128);
let x = usize::from_ne_bytes(block); // Really just a transmute
let lt = x.wrapping_sub(BM) & !x; // <= m
let xor_del = x ^ DEL;
let eq_del = xor_del.wrapping_sub(ONE) & !xor_del; // == DEL
offsetnz((lt | eq_del) & M128)
}
/// Check block to find offset of first non-zero byte
// NOTE: Curiously `block.trailing_zeros() >> 3` appears to be slower, maybe revisit
#[inline]
fn offsetnz(block: usize) -> usize {
// fast path optimistic case (common for long valid sequences)
if block == 0 {
return BLOCK_SIZE;
}
// perf: rust will unroll this loop
for (i, b) in block.to_ne_bytes().iter().copied().enumerate() {
if b != 0 {
return i;
}
}
unreachable!()
}
#[test]
fn test_is_header_value_block() {
let is_header_value_block = |b| match_header_value_char_8_swar(b) == BLOCK_SIZE;
// 0..32 => false
for b in 0..32_u8 {
assert!(!is_header_value_block([b; BLOCK_SIZE]), "b={}", b);
}
// 32..=126 => true
for b in 32..=126_u8 {
assert!(is_header_value_block([b; BLOCK_SIZE]), "b={}", b);
}
// 127 => false
assert!(!is_header_value_block([b'\x7F'; BLOCK_SIZE]), "b={}", b'\x7F');
// 128..=255 => true
for b in 128..=255_u8 {
assert!(is_header_value_block([b; BLOCK_SIZE]), "b={}", b);
}
#[cfg(target_pointer_width = "64")]
{
// A few sanity checks on non-uniform bytes for safe-measure
assert!(!is_header_value_block(*b"foo.com\n"));
assert!(!is_header_value_block(*b"o.com\r\nU"));
}
}
#[test]
fn test_is_uri_block() {
let is_uri_block = |b| match_uri_char_8_swar(b) == BLOCK_SIZE;
// 0..33 => false
for b in 0..33_u8 {
assert!(!is_uri_block([b; BLOCK_SIZE]), "b={}", b);
}
// 33..=126 => true
for b in 33..=126_u8 {
assert!(is_uri_block([b; BLOCK_SIZE]), "b={}", b);
}
// 127 => false
assert!(!is_uri_block([b'\x7F'; BLOCK_SIZE]), "b={}", b'\x7F');
// 128..=255 => true
for b in 128..=255_u8 {
assert!(is_uri_block([b; BLOCK_SIZE]), "b={}", b);
}
}
#[test]
fn test_offsetnz() {
let seq = [0_u8; BLOCK_SIZE];
for i in 0..BLOCK_SIZE {
let mut seq = seq;
seq[i] = 1;
let x = usize::from_ne_bytes(seq);
assert_eq!(offsetnz(x), i);
}
}

3692
vendor/httparse/tests/uri.rs vendored Normal file

File diff suppressed because it is too large Load Diff