Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.84 chores #29

Merged
merged 2 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,25 @@ jobs:
with:
toolchain: stable
override: true
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Run no-default-features tests with code coverage
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --no-fail-fast
env:
RUSTC_BOOTSTRAP: '1'
CARGO_INCREMENTAL: '0'
RUSTFLAGS: '-Zprofile -Cinstrument-coverage -Ccodegen-units=1 -Cllvm-args=--inline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
RUSTDOCFLAGS: '-Zprofile -Cinstrument-coverage -Ccodegen-units=1 -Cllvm-args=--inline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
command: llvm-cov
args: --no-report --no-default-features --no-fail-fast
- name: Run default tests with code coverage
uses: actions-rs/cargo@v1
with:
command: test
args: --all-features --no-fail-fast
env:
RUSTC_BOOTSTRAP: '1'
CARGO_INCREMENTAL: '0'
RUSTFLAGS: '-Zprofile -Cinstrument-coverage -Ccodegen-units=1 -Cllvm-args=--inline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
RUSTDOCFLAGS: '-Zprofile -Cinstrument-coverage -Ccodegen-units=1 -Cllvm-args=--inline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
- name: Run grcov
id: coverage
uses: rraval/grcov@master
command: llvm-cov
args: --no-report --all-features --no-fail-fast
- name: Generate Report
uses: actions-rs/cargo@v1
with:
command: llvm-cov
args: report --lcov --output-path lcov.info
- name: Coveralls upload
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ${{ steps.coverage.outputs.report }}
path-to-lcov: lcov.info
68 changes: 33 additions & 35 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
{:tasks
{:init (do (def code-cov-env
{"CARGO_INCREMENTAL" "0"
"RUSTFLAGS" "-Cinstrument-coverage -Copt-level=0 -Ccodegen-units=1 -Cllvm-args=--inline-threshold=0 -Clink-dead-code -Coverflow-checks=off"
"LLVM_PROFILE_FILE" "target/coverage/cargo-test-%p-%m.profraw"}))
:requires ([babashka.fs :as fs])
clean {:doc "Removes target folder"
:task (fs/delete-tree "target")}
test_lib_features (shell "cargo test --all-features --no-fail-fast")
test_lib_no_default_features (shell "cargo test --no-default-features --no-fail-fast")
cargo-test {:doc "Runs all cargo tests"
:depends [test_lib_features test_lib_no_default_features]}
cargo-fmt {:doc "Checks cargo fmt"
:task (shell "cargo fmt --check")}
cargo-clippy-all-features {:doc "Cargo clippy with all features"
:task (shell "cargo clippy --all-features -- --deny warnings")}
cargo-clippy-no-defaults {:doc "Cargo clippy with no default features"
:task (shell "cargo clippy --no-default-features -- --deny warnings")}
cargo-clippy-examples {:doc "Cargo clippy on examples"
:task (shell "cargo clippy --examples -- --deny warnings -A clippy::unwrap-used")}
clippy {:doc "Runs all variations of cargo clippy"
:depends [cargo-clippy-all-features cargo-clippy-no-defaults cargo-clippy-examples]}
cov-all-features {:doc "Coverage, all features"
:task (shell {:extra-env code-cov-env} "cargo test --all-features")}
cov-std-only {:doc "Coverage, std only"
:task (shell {:extra-env code-cov-env} "cargo test --no-default-features")}
cov-examples {:doc "Coverage, examples"
:task (shell {:extra-env code-cov-env} "cargo test --examples")}
clean-cov {:doc "Cleans all .profraw files and generated html"
:task (fs/delete-tree "target/coverage")}
grcov {:doc "Runs grcov to generate human readable html"
:task (shell "grcov target/coverage --binary-path ./target/debug/deps/ -s . -t html --branch --ignore-not-existing -o target/coverage/html")}
coverage {:doc "Generates coverage in human friendly html in target/coverage/"
:depends [clean-cov cov-all-features cov-std-only cov-examples grcov]}
test {:doc "Runs all tests and checks"
:depends [cargo-test cargo-fmt clippy]}}}
{:requires ([babashka.fs :as fs])
clean {:doc "Removes target folder"
:task (fs/delete-tree "target")}
test_all_features (shell "cargo test --all-features --no-fail-fast")
test_no_default_features (shell "cargo test --no-default-features --no-fail-fast")
cargo-test {:doc "Runs all cargo tests"
:depends [test_all_features test_no_default_features]}
cargo-fmt {:doc "Checks cargo fmt"
:task (shell "cargo fmt --check")}
clippy-all-features {:doc "Cargo clippy with all features"
:task (shell "cargo clippy --all-features -- --deny warnings")}
clippy-no-defaults {:doc "Cargo clippy with no default features"
:task (shell "cargo clippy --no-default-features -- --deny warnings")}
clippy-examples {:doc "Cargo clippy on examples"
:task (shell "cargo clippy --examples -- --deny warnings -A clippy::unwrap-used")}
clippy {:doc "Runs all variations of cargo clippy"
:depends [clippy-all-features clippy-no-defaults clippy-examples]}
cov-all-features {:doc "Coverage, all features"
:task (shell "cargo llvm-cov --no-report --all-features")}
cov-std-only {:doc "Coverage, std only"
:task (shell "cargo llvm-cov --no-report --no-default-features")}
cov-examples {:doc "Coverage, examples"
:task (shell "cargo llvm-cov --no-report --examples")}
cov-clean {:doc "Cleans all .profraw files and generated html"
:task (shell "cargo llvm-cov clean --workspace")}
cov-html {:doc "Runs llvm-cov to generate human readable html"
:depends [cov-clean cov-all-features cov-std-only]
:task (shell "cargo llvm-cov report --html")}
cov {:doc "Generates coverage and reports to the terminal"
:depends [cov-clean cov-all-features cov-std-only cov-examples]
:task (shell "cargo llvm-cov report")}
test {:doc "Runs all tests and checks"
:depends [cargo-test cargo-fmt clippy]}}}
5 changes: 1 addition & 4 deletions src/http/mime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,7 @@ impl AcceptQualityMimeType {
return None;
}

let qvalue = match QValue::parse(&rawq[2..]) {
Some(qvalue) => qvalue,
None => return None,
};
let qvalue = QValue::parse(&rawq[2..])?;

if mime == "*/*" {
data.push(AcceptQualityMimeType { value: AcceptMimeType::Wildcard, q: qvalue });
Expand Down
2 changes: 1 addition & 1 deletion src/http/response_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl ResponseBody {
pub fn content_length(&self) -> Option<u64> {
match self {
ResponseBody::FixedSizeBinaryData(data) => u64::try_from(data.len()).ok(),
ResponseBody::FixedSizeTextData(data) => u64::try_from(data.as_bytes().len()).ok(),
ResponseBody::FixedSizeTextData(data) => u64::try_from(data.len()).ok(),
ResponseBody::FixedSizeFile(_, sz) => Some(*sz),
_ => None,
}
Expand Down
10 changes: 2 additions & 8 deletions src/humpty_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,8 @@ impl HumptyServer {

stream.set_read_timeout(self.read_timeout)?;

let mut context = match RequestContext::new(
stream.as_ref(),
meta.as_ref().cloned(),
self.max_head_buffer_size,
) {
Ok(ctx) => ctx,
Err(err) => return Err(err),
};
let mut context =
RequestContext::new(stream.as_ref(), meta.as_ref().cloned(), self.max_head_buffer_size)?;
count += 1;

stream.set_read_timeout(self.request_body_io_timeout)?;
Expand Down
2 changes: 1 addition & 1 deletion tests/mime_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn test_acceptable_permits_group() {
fn test_acceptable_permits() {
assert!(AcceptMimeType::from(MimeGroup::Video).permits(AcceptMimeType::from(MimeType::VideoMp4)));
assert!(AcceptMimeType::from(MimeGroup::Video).permits(AcceptMimeType::from(MimeGroup::Video)));
assert!(AcceptMimeType::from(MimeGroup::Video).permits(&AcceptMimeType::from(MimeGroup::Video)));
assert!(AcceptMimeType::from(MimeGroup::Video).permits(AcceptMimeType::from(MimeGroup::Video)));
assert!(!AcceptMimeType::from(MimeGroup::Video).permits(AcceptMimeType::Wildcard));
assert!(AcceptMimeType::Wildcard.permits(AcceptMimeType::Wildcard));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct MockStream {

impl MockStream {
pub fn with_str(data: &str) -> Self {
Self::with_data(VecDeque::from_iter(data.to_string().bytes().into_iter()))
Self::with_data(VecDeque::from_iter(data.to_string().bytes()))
}

pub fn with_slice(data: &[u8]) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions tests/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn test_request_from_stream() {
let mut expected_headers = Vec::new();
expected_headers.push(Header::new(HeaderName::Host, "localhost"));

let collected_headers = request.get_all_headers().map(|a| a.clone()).collect::<Vec<_>>();
let collected_headers = request.get_all_headers().cloned().collect::<Vec<_>>();
assert_eq!(collected_headers, expected_headers);
}

Expand Down Expand Up @@ -68,7 +68,7 @@ fn test_proxied_request_from_stream() {
let mut expected_headers = Vec::new();
expected_headers.push(Header::new(HeaderName::Host, "localhost"));
expected_headers.push(Header::new("X-Forwarded-For", "9.10.11.12,13.14.15.16"));
let collected: Vec<Header> = request.get_all_headers().map(|h| h.clone()).collect();
let collected: Vec<Header> = request.get_all_headers().cloned().collect();

assert_eq!(collected, expected_headers);
}
2 changes: 1 addition & 1 deletion tests/tc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ static COUNTER: AtomicUsize = AtomicUsize::new(0);
fn dummy_route(ctx: &RequestContext) -> HumptyResult<Response> {
COUNTER.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
assert_eq!(HttpVersion::Http11, ctx.request_head().version());
Response::new(StatusCode::OK).with_body("Okay!").with_header("Fubar", "Dubar").into()
Response::new(StatusCode::OK).with_body("Okay!").with_header("Fubar", "Dubar")
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/tc29.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn tc29() {
})
.expect("ERROR");

let many_a = String::from_utf8(vec!['A' as u8; 513]).unwrap();
let many_a = String::from_utf8(vec![b'A'; 513]).unwrap();

let blub = format!("GET /{many_a} HTTP/1.1\r\n\r\n");

Expand Down
8 changes: 3 additions & 5 deletions tests/tc3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ fn dummy_route(ctx: &RequestContext) -> HumptyResult<Response> {
assert_eq!(HttpVersion::Http11, ctx.request_head().version());
assert_eq!(ctx.request_head().get_header("Hdr"), Some("test"));

Ok(
Response::new(StatusCode::OK)
.with_body(ResponseBody::from_slice("Okay!"))
.with_header("Connection", "Close")?,
)
Response::new(StatusCode::OK)
.with_body(ResponseBody::from_slice("Okay!"))
.with_header("Connection", "Close")
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/tc30.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn tc30() {
})
.expect("ERROR");

let many_a = String::from_utf8(vec!['A' as u8; 513]).unwrap();
let many_a = String::from_utf8(vec![b'A'; 513]).unwrap();

let blub = format!("GET / HTTP/1.1\r\nMany: {many_a}\r\n\r\n");

Expand Down
Loading