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

[http server]: export acl types + remove cors_max_age #466

Merged
merged 5 commits into from
Sep 15, 2021
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
2 changes: 1 addition & 1 deletion http-server/src/access_control/cors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl<T: Into<String>> From<T> for AccessControlAllowOrigin {

/// Headers allowed to access
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum AccessControlAllowHeaders {
pub enum AccessControlAllowHeaders {
/// Specific headers
Only(Vec<String>),
/// Any header
Expand Down
2 changes: 1 addition & 1 deletion http-server/src/access_control/hosts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl std::ops::Deref for Host {

/// Specifies if domains should be validated.
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) enum DomainsValidation<T> {
pub enum DomainsValidation<T> {
/// Allow only domains on the list.
AllowOnly(Vec<T>),
/// Disable domains validation completely.
Expand Down
15 changes: 2 additions & 13 deletions http-server/src/access_control/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@

//! Access control based on HTTP headers

mod cors;
pub(crate) mod cors;
pub(crate) mod hosts;
mod matcher;

pub(crate) use cors::{AccessControlAllowHeaders, AccessControlAllowOrigin};
use hosts::{AllowHosts, Host};

use cors::{AccessControlAllowHeaders, AccessControlAllowOrigin};
use hyper::header;
use jsonrpsee_utils::http_helpers;

Expand All @@ -41,7 +41,6 @@ use jsonrpsee_utils::http_helpers;
pub struct AccessControl {
allow_hosts: AllowHosts,
cors_allow_origin: Option<Vec<AccessControlAllowOrigin>>,
cors_max_age: Option<u32>,
cors_allow_headers: AccessControlAllowHeaders,
continue_on_invalid_cors: bool,
}
Expand Down Expand Up @@ -92,7 +91,6 @@ impl Default for AccessControl {
Self {
allow_hosts: AllowHosts::Any,
cors_allow_origin: None,
cors_max_age: None,
cors_allow_headers: AccessControlAllowHeaders::Any,
continue_on_invalid_cors: false,
}
Expand All @@ -104,7 +102,6 @@ impl Default for AccessControl {
pub struct AccessControlBuilder {
allow_hosts: AllowHosts,
cors_allow_origin: Option<Vec<AccessControlAllowOrigin>>,
cors_max_age: Option<u32>,
cors_allow_headers: AccessControlAllowHeaders,
continue_on_invalid_cors: bool,
}
Expand All @@ -114,7 +111,6 @@ impl Default for AccessControlBuilder {
Self {
allow_hosts: AllowHosts::Any,
cors_allow_origin: None,
cors_max_age: None,
cors_allow_headers: AccessControlAllowHeaders::Any,
continue_on_invalid_cors: false,
}
Expand Down Expand Up @@ -153,12 +149,6 @@ impl AccessControlBuilder {
self
}

/// Configure CORS max age.
pub fn cors_max_age(mut self, max_age: u32) -> Self {
self.cors_max_age = Some(max_age);
self
}

/// Configure which CORS header that is allowed.
pub fn cors_allow_header(mut self, header: String) -> Self {
let allow_headers = match self.cors_allow_headers {
Expand All @@ -183,7 +173,6 @@ impl AccessControlBuilder {
AccessControl {
allow_hosts: self.allow_hosts,
cors_allow_origin: self.cors_allow_origin,
cors_max_age: self.cors_max_age,
cors_allow_headers: self.cors_allow_headers,
continue_on_invalid_cors: self.continue_on_invalid_cors,
}
Expand Down
3 changes: 2 additions & 1 deletion http-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ mod server;
pub mod response;

pub use access_control::{
hosts::{AllowHosts, Host},
cors::{AccessControlAllowHeaders, AccessControlAllowOrigin},
hosts::{AllowHosts, DomainsValidation, Host},
AccessControl, AccessControlBuilder,
};
pub use jsonrpsee_types as types;
Expand Down