Unverified Commit 094b10db authored by Igor Aleksanov's avatar Igor Aleksanov Committed by GitHub
Browse files

Enable docs/debug/pub warnings for server and types crates (#360)



* Enable docs/debug/pub warnings for server and types crates

* Remove Debug bound on Notif

* Stick to deriving debug

* Update utils/src/server/rpc_module.rs

Co-authored-by: David's avatarDavid <dvdplm@gmail.com>

Co-authored-by: David's avatarDavid <dvdplm@gmail.com>
parent 1b89dec8
......@@ -161,7 +161,7 @@ impl<T: Into<String>> From<T> for AccessControlAllowOrigin {
/// Headers allowed to access
#[derive(Debug, Clone, PartialEq)]
pub enum AccessControlAllowHeaders {
pub(crate) enum AccessControlAllowHeaders {
/// Specific headers
Only(Vec<String>),
/// Any header
......@@ -207,7 +207,7 @@ impl<T> From<AllowCors<T>> for Option<T> {
}
/// Returns correct CORS header (if any) given list of allowed origins and current origin.
pub fn get_cors_allow_origin(
pub(crate) fn get_cors_allow_origin(
origin: Option<&str>,
host: Option<&str>,
allowed: &Option<Vec<AccessControlAllowOrigin>>,
......@@ -251,7 +251,7 @@ pub fn get_cors_allow_origin(
}
/// Validates if the `AccessControlAllowedHeaders` in the request are allowed.
pub fn get_cors_allow_headers<T: AsRef<str>, O, F: Fn(T) -> O>(
pub(crate) fn get_cors_allow_headers<T: AsRef<str>, O, F: Fn(T) -> O>(
mut headers: impl Iterator<Item = T>,
requested_headers: impl Iterator<Item = T>,
cors_allow_headers: &AccessControlAllowHeaders,
......
......@@ -141,7 +141,7 @@ impl std::ops::Deref for Host {
/// Specifies if domains should be validated.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum DomainsValidation<T> {
pub(crate) enum DomainsValidation<T> {
/// Allow only domains on the list.
AllowOnly(Vec<T>),
/// Disable domains validation completely.
......@@ -158,7 +158,7 @@ impl<T> From<Option<Vec<T>>> for DomainsValidation<T> {
}
/// Returns `true` when `Host` header is whitelisted in `allow_hosts`.
pub fn is_host_valid(host: Option<&str>, allow_hosts: &AllowHosts) -> bool {
pub(crate) fn is_host_valid(host: Option<&str>, allow_hosts: &AllowHosts) -> bool {
match host {
None => false,
Some(ref host) => match allow_hosts {
......@@ -169,7 +169,7 @@ pub fn is_host_valid(host: Option<&str>, allow_hosts: &AllowHosts) -> bool {
}
/// Allowed hosts for http header 'host'
#[derive(Clone)]
#[derive(Clone, Debug)]
pub enum AllowHosts {
/// Allow requests from any host
Any,
......
......@@ -29,15 +29,16 @@ use log::warn;
use std::{fmt, hash};
/// Pattern that can be matched to string.
pub trait Pattern {
pub(crate) trait Pattern {
/// Returns true if given string matches the pattern.
fn matches<T: AsRef<str>>(&self, other: T) -> bool;
}
#[derive(Clone)]
pub struct Matcher(Option<GlobMatcher>, String);
pub(crate) struct Matcher(Option<GlobMatcher>, String);
impl Matcher {
pub fn new(string: &str) -> Matcher {
pub(crate) fn new(string: &str) -> Matcher {
Matcher(
GlobBuilder::new(string)
.case_insensitive(true)
......
......@@ -27,17 +27,17 @@
//! Access control based on HTTP headers
mod cors;
mod hosts;
pub(crate) mod hosts;
mod matcher;
pub use cors::{AccessControlAllowHeaders, AccessControlAllowOrigin};
pub use hosts::{AllowHosts, Host};
pub(crate) use cors::{AccessControlAllowHeaders, AccessControlAllowOrigin};
use hosts::{AllowHosts, Host};
use hyper::header;
use jsonrpsee_utils::hyper_helpers;
/// Define access on control on HTTP layer.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct AccessControl {
allow_hosts: AllowHosts,
cors_allow_origin: Option<Vec<AccessControlAllowOrigin>>,
......@@ -100,6 +100,7 @@ impl Default for AccessControl {
}
/// Convenience builder pattern
#[derive(Debug)]
pub struct AccessControlBuilder {
allow_hosts: AllowHosts,
cors_allow_origin: Option<Vec<AccessControlAllowOrigin>>,
......
......@@ -24,11 +24,22 @@
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#![warn(missing_docs, missing_debug_implementations, unreachable_pub)]
//! # jsonrpsee-http-server
//!
//! `jsonrpsee-http-server` is a [JSON RPC](https://www.jsonrpc.org/specification) HTTPS server library that's is built for `async/await`.
mod access_control;
mod response;
mod server;
pub use access_control::{AccessControl, AccessControlBuilder, AllowHosts, Host};
/// Common builders for RPC responses.
pub mod response;
pub use access_control::{
hosts::{AllowHosts, Host},
AccessControl, AccessControlBuilder,
};
pub use jsonrpsee_types::{Error, TEN_MB_SIZE_BYTES};
pub use jsonrpsee_utils::server::rpc_module::{RpcModule, SyncMethods};
pub use server::{Builder as HttpServerBuilder, Server as HttpServer};
......
......@@ -51,6 +51,7 @@ use std::{
};
/// Builder to create JSON-RPC HTTP server.
#[derive(Debug)]
pub struct Builder {
access_control: AccessControl,
max_request_body_size: u32,
......@@ -78,6 +79,7 @@ impl Builder {
self
}
/// Finalizes the configuration of the server.
pub fn build(self, addr: SocketAddr) -> Result<Server, Error> {
let domain = Domain::for_address(addr);
let socket = Socket::new(domain, Type::STREAM, None)?;
......@@ -109,6 +111,8 @@ impl Default for Builder {
}
}
/// An HTTP JSON RPC server.
#[derive(Debug)]
pub struct Server {
/// Hyper server.
listener: HyperBuilder<AddrIncoming>,
......
//! jsonrpsee wrapper crate.
/// JSON RPC HTTP client.
#[cfg(feature = "client")]
pub use http_client;
/// JSON RPC WebSocket client.
#[cfg(feature = "client")]
pub use ws_client;
/// JSON RPC HTTP server.
#[cfg(feature = "server")]
pub use http_server;
/// JSON RPC WebSocket server.
#[cfg(feature = "server")]
pub use ws_server;
/// Set of RPC methods that can be mounted to the server.
#[cfg(feature = "server")]
pub use utils::server::rpc_module::RpcModule;
/// Procedural macros for JSON RPC implementations.
#[cfg(feature = "macros")]
pub use proc_macros;
/// Common types used to implement JSON RPC server and client.
#[cfg(feature = "macros")]
pub use types;
......@@ -6,6 +6,7 @@ use serde::de::DeserializeOwned;
use serde_json::Value as JsonValue;
/// Active subscription on a Client.
#[derive(Debug)]
pub struct Subscription<Notif> {
/// Channel to send requests to the background task.
pub to_back: mpsc::Sender<FrontToBack>,
......@@ -18,6 +19,7 @@ pub struct Subscription<Notif> {
}
/// Active NotificationHandler on a Client.
#[derive(Debug)]
pub struct NotificationHandler<Notif> {
/// Channel to send requests to the background task.
pub to_back: mpsc::Sender<FrontToBack>,
......
//! Shared types in `jsonrpsee` for clients, servers and utilities.
#![deny(unsafe_code)]
#![warn(missing_docs)]
#![warn(missing_docs, missing_debug_implementations)]
extern crate alloc;
......
......@@ -15,7 +15,7 @@ pub struct JsonRpcResponse<'a, T> {
}
/// JSON-RPC subscription response.
#[derive(Serialize)]
#[derive(Serialize, Debug)]
pub struct JsonRpcSubscriptionResponse<'a> {
/// JSON-RPC version.
pub jsonrpc: TwoPointZero,
......
//! Shared utilities for `jsonrpsee`.
#![warn(missing_docs)]
#![warn(missing_docs, missing_debug_implementations, unreachable_pub)]
#[cfg(all(feature = "hyper13", feature = "hyper14"))]
compile_error!("feature `hyper13` and `hyper14` are mutably exclusive");
......
......@@ -52,6 +52,14 @@ pub struct Methods {
async_methods: AsyncMethods,
}
impl std::fmt::Debug for Methods {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// Including types only is sufficient, as it contains information
// about the registered methods and if they are sync or async.
f.debug_struct("Methods").field("method_types", &self.method_types).finish()
}
}
impl Methods {
/// Creates a new empty [`Methods`].
pub fn new() -> Self {
......@@ -110,6 +118,7 @@ impl Methods {
/// Sets of JSON-RPC methods can be organized into a "module"s that are in turn registered on the server or,
/// alternatively, merged with other modules to construct a cohesive API. [`RpcModule`] wraps an additional context
/// argument that can be used to access data during call execution.
#[derive(Debug)]
pub struct RpcModule<Context> {
ctx: Arc<Context>,
methods: Methods,
......@@ -297,6 +306,7 @@ impl<Context: Send + Sync + 'static> RpcModule<Context> {
}
/// Represents a single subscription.
#[derive(Debug)]
pub struct SubscriptionSink {
/// Sink.
inner: mpsc::UnboundedSender<String>,
......
......@@ -24,6 +24,12 @@
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#![warn(missing_debug_implementations, missing_docs, unreachable_pub)]
//! # jsonrpsee-ws-server
//!
//! `jsonrpsee-ws-server` is a [JSON RPC](https://www.jsonrpc.org/specification) WebSocket server library that's is built for `async/await`.
extern crate alloc;
mod server;
......
......@@ -43,6 +43,8 @@ use jsonrpsee_utils::server::{
rpc_module::MethodType,
};
/// A WebSocket JSON RPC server.
#[derive(Debug)]
pub struct Server {
methods: Methods,
listener: TcpListener,
......
......@@ -25,7 +25,7 @@ impl std::error::Error for MyAppError {}
/// Spawns a dummy `JSONRPC v2 WebSocket`
/// It has two hardcoded methods: "say_hello" and "add"
pub async fn server() -> SocketAddr {
async fn server() -> SocketAddr {
let mut server = WsServer::new("127.0.0.1:0").with_default_timeout().await.unwrap().unwrap();
let mut module = RpcModule::new(());
module
......@@ -69,7 +69,7 @@ pub async fn server() -> SocketAddr {
}
/// Run server with user provided context.
pub async fn server_with_context() -> SocketAddr {
async fn server_with_context() -> SocketAddr {
let mut server = WsServer::new("127.0.0.1:0").with_default_timeout().await.unwrap().unwrap();
let ctx = TestContext;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment