Skip to content

Commit 8e34b4c

Browse files
Move request handler module into the server crate
The request handler is used by the http server. Keep the http crate simple. Only include the http abstractions needed by both the server and the client.
1 parent f234837 commit 8e34b4c

File tree

9 files changed

+23
-31
lines changed

9 files changed

+23
-31
lines changed

crates/http/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "http-utils"
3-
version = "0.1.2"
3+
version = "0.2.0"
44
edition = "2021"
55
description = "Http utils"
66
authors = ["Saúl Valdelvira <saul@saulv.es>"]
@@ -13,10 +13,7 @@ path = "src/lib.rs"
1313

1414
[dependencies]
1515
base64 = { package = "rb64", version = ">=0.1.0", git = "https://github.com/saulvaldelvira/rb64" }
16-
mime = { package = "rmime", version = ">=0.1.0", path = "../mime" }
1716
url = { package = "url-utils", version = ">=0.1.0", path = "../url" }
18-
html = { package = "rhtml", version = ">=0.1.0", path = "../html" }
19-
regexpr = { version = ">=0.3.3", git = "https://github.com/saulvaldelvira/regexpr" }
2017

2118
[dependencies.builders]
2219
package = "builders"

crates/http/src/error.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ macro_rules! err {
4343
};
4444
}
4545

46-
use regexpr::RegexError;
47-
4846
impl From<io::Error> for HttpError {
4947
#[inline]
5048
fn from(value: io::Error) -> Self {
@@ -82,12 +80,6 @@ impl From<Cow<'static, str>> for HttpError {
8280
}
8381
}
8482

85-
impl From<RegexError> for HttpError {
86-
fn from(value: RegexError) -> Self {
87-
Self::new(value.inner().clone())
88-
}
89-
}
90-
9183
impl Debug for HttpError {
9284
#[inline]
9385
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {

crates/http/src/request/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub mod handler;
1+
/* pub mod handler; */
22
use builders::Builder;
33
mod parse;
44
use std::{

crates/server/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22
name = "http-srv"
33
description = "Http Server"
44
authors = ["Saúl Valdelvira <saul@saulv.es>"]
5-
version = "0.3.3"
5+
version = "0.4.0"
66
edition = "2021"
77
license = "MIT"
88
readme = "README"
99
repository = "https://git.saulv.es/http-server"
1010

1111
[dependencies]
1212
http.workspace = true
13+
mime = { package = "rmime", version = ">=0.1.0", path = "../mime" }
14+
regexpr = { version = ">=0.3.3", git = "https://github.com/saulvaldelvira/regexpr" }
1315
pool = { package = "job-pool", version = ">=0.1.0", git = "https://github.com/saulvaldelvira/job-pool" }
1416
jsonrs = { package = "jsonrs", version = ">=0.1.4", git = "https://github.com/saulvaldelvira/json.rs" }
1517
delay_init = { package = "delay_init" , version = ">=0.2.0", git = "https://github.com/saulvaldelvira/delay-init" }
18+
base64 = { package = "rb64", version = ">=0.1.0", git = "https://github.com/saulvaldelvira/rb64" }
19+
url = { package = "url-utils", version = ">=0.1.0", path = "../url" }
20+
html = { package = "rhtml", version = ">=0.1.0", path = "../html" }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{err, HttpRequest, Result};
1616
/// # Example
1717
/// ```
1818
/// use http::*;
19-
/// use http::request::handler::*;
19+
/// use http_srv::handler::*;
2020
///
2121
/// let auth = AuthConfig::of_list(&[("user", "passwd")]);
2222
///
File renamed without changes.
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ use std::{
1212
};
1313

1414
pub use auth::AuthConfig;
15+
use http::HttpMethod;
1516
use mime::Mime;
1617
use regexpr::Regex;
1718

1819
use self::{indexing::index_of, ranges::get_range_for};
19-
use crate::{
20-
request::{HttpMethod, HttpRequest},
21-
Result,
22-
};
20+
use crate::{request::HttpRequest, Result};
2321

2422
/* /// HandlerFunc trait */
2523
/* /// */
@@ -69,7 +67,8 @@ pub struct UrlMatcher(UrlMatcherInner);
6967

7068
impl UrlMatcher {
7169
pub fn regex(src: &str) -> Result<Self> {
72-
Ok(UrlMatcher(UrlMatcherInner::Regex(Regex::compile(src)?)))
70+
let regex = Regex::compile(src).map_err(|err| err.to_string())?;
71+
Ok(UrlMatcher(UrlMatcherInner::Regex(regex)))
7372
}
7473
#[must_use]
7574
pub fn literal(src: String) -> Self {
@@ -96,7 +95,7 @@ impl From<String> for UrlMatcher {
9695
///
9796
/// # Example
9897
/// ```
99-
/// use http::request::handler::{self,*};
98+
/// use http_srv::handler::{self,*};
10099
/// use http::request::HttpRequest;
101100
/// use http::HttpMethod;
102101
///

crates/server/src/lib.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,17 @@
3434
pub use http::{self, request, response, HttpRequest, HttpResponse};
3535
pub mod config;
3636

37+
pub mod handler;
38+
3739
#[doc(hidden)]
3840
pub mod prelude {
39-
pub use http::{
40-
request::{
41-
handler::{self, AuthConfig, Handler},
42-
HttpRequest,
43-
},
44-
response::*,
45-
*,
46-
};
41+
pub use http::{request::HttpRequest, response::*, *};
4742

48-
pub use crate::{config::*, HttpServer};
43+
pub use crate::{
44+
config::*,
45+
handler::{self, AuthConfig, Handler},
46+
HttpServer,
47+
};
4948
}
5049
use prelude::*;
5150

@@ -75,7 +74,7 @@ use log::prelude::*;
7574
/// ```rust,no_run
7675
/// use http_srv::HttpServer;
7776
/// use http_srv::ServerConfig;
78-
/// use http_srv::http::request::handler::Handler;
77+
/// use http_srv::handler::Handler;
7978
/// use http_srv::request::HttpRequest;
8079
///
8180
/// let config = ServerConfig::default();

0 commit comments

Comments
 (0)