Skip to content

Commit

Permalink
Add tiny_http fork with rustls support, ssl example
Browse files Browse the repository at this point in the history
  • Loading branch information
travispaul committed Jan 28, 2022
1 parent 34d3134 commit 4d264b9
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ categories = ["web-programming::http-server", "web-programming::websocket"]
default = ["gzip", "brotli"]
gzip = ["deflate"]
ssl = ["tiny_http/ssl"]
ssl-rustls = ["tiny_http/ssl-rustls"]

[dependencies]
base64 = "0.13"
brotli = { version = "3.3.2", optional = true }
chrono = { version = "0.4.19", default-features = false }
chrono = { version = "0.4.19", default-features = false, features = ["clock"]}

This comment has been minimized.

Copy link
@travispaul

travispaul Jan 28, 2022

Author Member

After upgrading tiny_http from 0.8.1 to 0.10.0 I needed to add back the clock feature of Chrono else:

   Compiling rouille v3.5.0 (/opt/project/rouille)
error[E0599]: no function or associated item named `now` found for struct `Utc` in the current scope
  --> src/log.rs:49:22
   |
49 |         chrono::Utc::now().format("%Y-%m-%d %H:%M:%S%.6f"),
   |                      ^^^ function or associated item not found in `Utc`

Which seems to be related to an update of the time library in tiny_http based on a quick diff of cargo tree -e features --edges no-dev output between both versions installed in this project.

filetime = "0.2.0"
deflate = { version = "0.9", optional = true, features = ["gzip"] }
multipart = { version = "0.18", default-features = false, features = ["server"] }
Expand All @@ -29,7 +30,7 @@ serde_derive = "1"
serde_json = "1"
sha1 = "0.6.0"
time = { version = "0.3.5", features = [ "local-offset" ] }
tiny_http = "0.8.1"
tiny_http = { git = "ssh://[email protected]/travispaul-forks/tiny-http.git", branch = "rustls20" }
url = "2"
threadpool = "1"
num_cpus = "1"
Expand Down
23 changes: 23 additions & 0 deletions examples/ssl-cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-----BEGIN CERTIFICATE-----
MIIDxzCCAq+gAwIBAgIUVB6JBT6sYv0g4IGfZgjelceiqBQwDQ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WU2HKFT85sDIygmv0hmuI0dF+9lpqfPguhx6iLOoFyXkbgqF
RDWe8V0/GtEnX4PckdyyYk/uFX5aKMeW5dBY6GL9YDRcZvTLsjJi1wj3OcDsr7n5
ULkGWiWdQScpkrGWOPoM72r6yyFi5P/RCBI/p0LBseARXAAedgC8tTK6DpfRXe1M
BumieRdjmHDbE+4=
-----END CERTIFICATE-----
28 changes: 28 additions & 0 deletions examples/ssl-key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDYI3PYWbRML3tr
rIza3PtsOG0/XyYtrlUN3h3bRAoqwcR65q0m0njsob0z5qJ8qfNS0L+disxwy8cF
UphaCZKyCq56qks8P8p7qgacpIVd0yjyykgmYsqkJhrnEyMTlzPWRAedcwr6vtoy
+L9pwbnom2Nks1xujEgI0UQuXsw02LyDB9drh9FOGt1DCAj0xDJbsvpk+EtRBmS0
49+/uiUAP9cWM2QIn2QBhCkXAndKuX/SFFfBp52I6bRRbMCSRexAaRMWSJccE5+3
OFJ/Mo2DkwI/WMOjogMujFb/DUhdQ3hpmMFBR5unlFJr/mDv0/fbHbdXaXX9fvNO
xWuti9XfAgMBAAECggEBALRhyiHKo71dd0yigh96g96KrSpRV4SSVOuw7wv6md2b
P0Yu1F1tFHywcz4ogn02PRtlmjV6DCsq9ltL1lh2WtZ6MamwDAApYOyaNtBuQdvP
CgKurU5T7rjWEGe/QevsqddtiUlvJL+lnmch0GYLxwMJBAeb5U1hiBDLzXJBrX1/
xstCJzYC1MO3zRNuoNudpZyMU18BCbk1E+XMu/yPyJJPm5VSxS3Qe0RIX0nqC3hd
RjwiTGYIqHX/hTFuZta+lNwVSx/8TJY6wTq69r6mGf0hudXz9A0SEhSVdkU77yFE
NLCTRGD8xkF1bJliT57dGofheSrn4+ATR6eMYzsGmYECgYEA/0Ao+dccjMgqiyhR
K3TTaikSSvvTOY/muISvovlpDe1U10+HIPMfGIJUVOE7p4oAbg9W70x8hMox+0hN
yERLp4Pq9skkwxfmGjA0ooKJt0e0Ux1A5LiboLUPGlBsHwNcLqno/vj4WK/TGdZu
51zG1zvBrSIMLtT5QChsy+zTtsECgYEA2MXlkgy8W7/9BRcdzCXj2Uan5L+H6KT3
fXHYWc5yp0QBl6dqNCtPJ2lIpZ+qrNzJ1QZM56+qPEftOFOmhnz4+U6SAaKc/75n
bAL//ggMQwHzMus6ufhXJC3AYSduq9e1hnOC+K7Hc3dPLPkJGjVZVC2kXhACTwuL
aBbi5EmWVJ8CgYByk3BRRdgQ8cD3Gi/lW9mSq8EEW6njCs88QIM+msoncENHKvGz
Pq7Up5wHRdsrR20N+mDBpgm26bQp4bjYjp+PIE4WXQ/daxrk4oKd+A6tcMhnDpiU
krF5IA0ZeMQv36g/YhGucj+4P6R40qKRxDmVX8N+XewuEXeY7wx3NWWLgQKBgQC4
DqA0eDfet49AqTYVxv5F2GZqJe5iLOAvVWDcMBzNxUKM4AufLD7TOeQDLSUgDYAa
LnVSK6eh83iKYQx+GNLV7E6wsMAZrjPmVE3EBlVS9+7lhzGgAisLfwVf+LlRk6B/
/shwGwcjFWTWzMVbyXyFqxNrArDTKPw/b19LcugABQKBgQD8ARwEoZRyl8kuLyLh
33FRUAVTvuCU1KvEl9CU6BcmEDNcI/O/IYOeOUXYeIeNyATNH2L8A++i53EptpMd
wVxEIE2YBHD2t6+OcTjFSey7/6BejBUExxMVyWnUZMq3Xvf30ecfvacSb/DexqAG
yos+VoW4PIphdW3NBfE1hlLDZQ==
-----END PRIVATE KEY-----
66 changes: 66 additions & 0 deletions examples/ssl-simple-form.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#[macro_use]
extern crate rouille;

use std::io;

fn main() {
// This example demonstrates how to handle HTML forms.

// Note that like all examples we only listen on `localhost`, so you can't access this server
// from another machine than your own.
println!("Now listening on localhost:8000");

let server = rouille::Server::new_ssl("localhost:8000", move |request| {
rouille::log(&request, io::stdout(), || {
router!(request,
(GET) (/) => {
// When viewing the home page, we return an HTML document described below.
rouille::Response::html(FORM)
},

(POST) (/submit) => {
// This is the route that is called when the user submits the form of the
// home page.

// We query the data with the `post_input!` macro. Each field of the macro
// corresponds to an element of the form.
// If the macro returns an error (for example if a field is missing, which
// can happen if you screw up the form or if the user made a manual request)
// we return a 400 response.
let data = try_or_400!(post_input!(request, {
txt: String,
files: Vec<rouille::input::post::BufferedFile>,
}));

// We just print what was received on stdout. Of course in a real application
// you probably want to process the data, eg. store it in a database.
println!("Received data: {:?}", data);

rouille::Response::html("Success! <a href=\"/\">Go back</a>.")
},

_ => rouille::Response::empty_404()
)
})
}, include_bytes!("ssl-cert.pem").to_vec(), include_bytes!("ssl-key.pem").to_vec()).unwrap();

server.run();
}

// The HTML document of the home page.
static FORM: &'static str = r#"
<html>
<head>
<title>Form</title>
</head>
<body>
<form action="submit" method="POST" enctype="multipart/form-data">
<p><input type="text" name="txt" placeholder="Some text" /></p>
<p><input type="file" name="files" multiple /></p>
<p><button>Upload</button></p>
</form>
</body>
</html>
"#;
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ where
///
/// Returns an error if there was an error while creating the listening socket, for example if
/// the port is already in use.
#[cfg(feature = "ssl")]
#[cfg(any(feature = "ssl", feature = "ssl-rustls"))]
pub fn new_ssl<A>(
addr: A,
handler: F,
Expand Down

0 comments on commit 4d264b9

Please sign in to comment.