Skip to content
Open
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
16 changes: 13 additions & 3 deletions ferron/src/modules/default_handler_checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,26 @@ impl ServerModuleHandlers for DefaultHandlerChecksModuleHandlers {
.response(
Response::builder()
.status(StatusCode::NO_CONTENT)
.header(header::ALLOW, "GET, POST, HEAD, OPTIONS")
.header(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate Code - Priority: High
This block of code is duplicated in ferron/src/request_handler.rs starting at line 805.

header::ALLOW,
"GET, POST, HEAD, OPTIONS, PUT, PATCH, DELETE",
)
.body(Empty::new().map_err(|e| match e {}).boxed())
.unwrap_or_default(),
)
.build(),
),
&Method::GET | &Method::POST | &Method::HEAD => Ok(ResponseData::builder(request).build()),
&Method::GET
| &Method::POST
| &Method::HEAD
| &Method::PUT
| &Method::PATCH
| &Method::DELETE => Ok(ResponseData::builder(request).build()),
_ => {
let mut header_map = HeaderMap::new();
if let Ok(header_value) = HeaderValue::from_str("GET, POST, HEAD, OPTIONS") {
if let Ok(header_value) =
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate Code - Priority: High
This block of code is duplicated in ferron/src/request_handler.rs starting at line 813.

HeaderValue::from_str("GET, POST, HEAD, OPTIONS, PUT, PATCH, DELETE")
{
header_map.insert(header::ALLOW, header_value);
};
Ok(
Expand Down
9 changes: 7 additions & 2 deletions ferron/src/request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,12 +802,17 @@ async fn request_handler_wrapped(
let response = match request.method() {
&Method::OPTIONS => Response::builder()
.status(StatusCode::NO_CONTENT)
.header(header::ALLOW, "GET, POST, HEAD, OPTIONS")
.header(
header::ALLOW,
"GET, POST, HEAD, OPTIONS, PUT, PATCH, DELETE",
)
.body(Empty::new().map_err(|e| match e {}).boxed())
.unwrap_or_default(),
_ => {
let mut header_map = HeaderMap::new();
if let Ok(header_value) = HeaderValue::from_str("GET, POST, HEAD, OPTIONS") {
if let Ok(header_value) =
HeaderValue::from_str("GET, POST, HEAD, OPTIONS, PUT, PATCH, DELETE")
{
header_map.insert(header::ALLOW, header_value);
};
generate_error_response(StatusCode::BAD_REQUEST, &combined_config, &Some(header_map)).await
Expand Down