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

feat(ic-http-certification): add http response convenience methods #398

Merged
merged 5 commits into from
Dec 9, 2024
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
12 changes: 2 additions & 10 deletions examples/http-certification/custom-assets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,7 @@ fn create_asset_response(
) -> HttpResponse {
let headers = get_asset_headers(additional_headers, body.len(), cel_expr);

HttpResponse::builder()
.with_status_code(StatusCode::OK)
.with_headers(headers)
.with_body(body)
.build()
HttpResponse::ok(body, headers).build()
}
```

Expand Down Expand Up @@ -544,11 +540,7 @@ fn create_uncertified_response() -> HttpResponse<'static> {
DefaultCelBuilder::skip_certification().to_string(),
);

HttpResponse::builder()
.with_status_code(StatusCode::OK)
.with_headers(headers)
.with_body(body)
.build()
HttpResponse::ok(body, headers).build()
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ic_cdk::{
use ic_http_certification::{
utils::add_v2_certificate_header, DefaultCelBuilder, DefaultResponseCertification,
DefaultResponseOnlyCelExpression, HeaderField, HttpCertification, HttpCertificationPath,
HttpCertificationTree, HttpCertificationTreeEntry, HttpRequest, HttpResponse, StatusCode,
HttpCertificationTree, HttpCertificationTreeEntry, HttpRequest, HttpResponse,
CERTIFICATE_EXPRESSION_HEADER_NAME,
};
use include_dir::{include_dir, Dir};
Expand Down Expand Up @@ -375,11 +375,7 @@ fn create_uncertified_response() -> HttpResponse<'static> {
DefaultCelBuilder::skip_certification().to_string(),
);

HttpResponse::builder()
.with_status_code(StatusCode::OK)
.with_headers(headers)
.with_body(body)
.build()
HttpResponse::ok(body, headers).build()
}

fn get_asset_headers(
Expand Down Expand Up @@ -412,9 +408,5 @@ fn create_asset_response(
) -> HttpResponse {
let headers = get_asset_headers(additional_headers, body.len(), cel_expr);

HttpResponse::builder()
.with_status_code(StatusCode::OK)
.with_headers(headers)
.with_body(body)
.build()
HttpResponse::ok(body, headers).build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ic_cdk::{
};
use ic_http_certification::{
utils::{add_skip_certification_header, skip_certification_certified_data},
HttpResponse, StatusCode,
HttpResponse,
};

#[init]
Expand Down Expand Up @@ -54,9 +54,5 @@ fn create_response() -> HttpResponse<'static> {
("content-type".to_string(), "text/html".to_string())
];

HttpResponse::builder()
.with_status_code(StatusCode::OK)
.with_headers(headers)
.with_body(body)
.build()
HttpResponse::ok(body, headers).build()
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod tests {
use ic_certificate_verification::CertificateVerificationError;
use ic_certification_testing::{CertificateBuilder, CertificateData};
use ic_http_certification::{HttpRequest, HttpResponse, StatusCode, CERTIFICATE_HEADER_NAME};
use ic_http_certification::{HttpRequest, HttpResponse, CERTIFICATE_HEADER_NAME};
use ic_response_verification::types::{VerificationInfo, VerifiedResponse};
use ic_response_verification::verify_request_response_pair;
use ic_response_verification::ResponseVerificationError;
Expand Down Expand Up @@ -41,11 +41,11 @@ mod tests {

let request = HttpRequest::get(path).build();

let response = HttpResponse::builder()
.with_status_code(StatusCode::OK)
.with_body(body.as_bytes())
.with_headers(vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)])
.build();
let response = HttpResponse::ok(
body.as_bytes(),
vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)],
)
.build();
let expected_response = VerifiedResponse {
status_code: None,
body: response.body().to_vec(),
Expand Down Expand Up @@ -99,11 +99,11 @@ mod tests {

let request = HttpRequest::get(encoded_path).build();

let response = HttpResponse::builder()
.with_status_code(StatusCode::OK)
.with_body(body.as_bytes())
.with_headers(vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)])
.build();
let response = HttpResponse::ok(
body.as_bytes(),
vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)],
)
.build();
let expected_response = VerifiedResponse {
status_code: None,
body: response.body().to_vec(),
Expand Down Expand Up @@ -156,11 +156,11 @@ mod tests {

let request = HttpRequest::get("/").build();

let response = HttpResponse::builder()
.with_status_code(StatusCode::OK)
.with_body(body.as_bytes())
.with_headers(vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)])
.build();
let response = HttpResponse::ok(
body.as_bytes(),
vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)],
)
.build();
let expected_response = VerifiedResponse {
status_code: None,
body: response.body().to_vec(),
Expand Down Expand Up @@ -213,11 +213,11 @@ mod tests {

let request = HttpRequest::get(path).build();

let response = HttpResponse::builder()
.with_status_code(StatusCode::OK)
.with_body(b"Hello IC!")
.with_headers(vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)])
.build();
let response = HttpResponse::ok(
b"Hello IC!",
vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)],
)
.build();

let result = verify_request_response_pair(
request,
Expand Down Expand Up @@ -262,11 +262,11 @@ mod tests {

let request = HttpRequest::get(path).build();

let response = HttpResponse::builder()
.with_status_code(StatusCode::OK)
.with_body(body.as_bytes())
.with_headers(vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)])
.build();
let response = HttpResponse::ok(
body.as_bytes(),
vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)],
)
.build();

let result = verify_request_response_pair(
request,
Expand Down Expand Up @@ -315,11 +315,11 @@ mod tests {

let request = HttpRequest::get(path).build();

let response = HttpResponse::builder()
.with_status_code(StatusCode::OK)
.with_body(body.as_bytes())
.with_headers(vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)])
.build();
let response = HttpResponse::ok(
body.as_bytes(),
vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)],
)
.build();

let result = verify_request_response_pair(
request,
Expand Down Expand Up @@ -370,11 +370,11 @@ mod tests {

let request = HttpRequest::get(path).build();

let response = HttpResponse::builder()
.with_status_code(StatusCode::OK)
.with_body(body.as_bytes())
.with_headers(vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)])
.build();
let response = HttpResponse::ok(
body.as_bytes(),
vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)],
)
.build();

let result = verify_request_response_pair(
request,
Expand Down Expand Up @@ -423,11 +423,11 @@ mod tests {

let request = HttpRequest::get(path).build();

let response = HttpResponse::builder()
.with_status_code(StatusCode::OK)
.with_body(body.as_bytes())
.with_headers(vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)])
.build();
let response = HttpResponse::ok(
body.as_bytes(),
vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)],
)
.build();

let result = verify_request_response_pair(
request,
Expand Down Expand Up @@ -473,11 +473,11 @@ mod tests {

let request = HttpRequest::get(path).build();

let response = HttpResponse::builder()
.with_status_code(StatusCode::OK)
.with_body(body.as_bytes())
.with_headers(vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)])
.build();
let response = HttpResponse::ok(
body.as_bytes(),
vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)],
)
.build();

let result = verify_request_response_pair(
request,
Expand Down Expand Up @@ -521,11 +521,11 @@ mod tests {

let request = HttpRequest::get(path).build();

let response = HttpResponse::builder()
.with_status_code(StatusCode::OK)
.with_body(body.as_bytes())
.with_headers(vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)])
.build();
let response = HttpResponse::ok(
body.as_bytes(),
vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)],
)
.build();

let result = verify_request_response_pair(
request,
Expand Down Expand Up @@ -569,11 +569,11 @@ mod tests {

let request = HttpRequest::get(path).build();

let response = HttpResponse::builder()
.with_status_code(StatusCode::OK)
.with_body(body.as_bytes())
.with_headers(vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)])
.build();
let response = HttpResponse::ok(
body.as_bytes(),
vec![(CERTIFICATE_HEADER_NAME.into(), certificate_header)],
)
.build();

let result = verify_request_response_pair(
request,
Expand Down
Loading
Loading