-
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update force_https doc and add example (#884)
- Loading branch information
1 parent
614688a
commit 2d8cc24
Showing
6 changed files
with
124 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "example-force-https" | ||
version.workspace = true | ||
edition.workspace = true | ||
publish.workspace = true | ||
|
||
|
||
[dependencies] | ||
salvo = { workspace = true, features = ["rustls", "force-https"] } | ||
tokio = { workspace = true, features = ["macros"] } | ||
tracing.workspace = true | ||
tracing-subscriber.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIEADCCAmigAwIBAgICAcgwDQYJKoZIhvcNAQELBQAwLDEqMCgGA1UEAwwhcG9u | ||
eXRvd24gUlNBIGxldmVsIDIgaW50ZXJtZWRpYXRlMB4XDTIyMDgxMTAwMjYwOVoX | ||
DTI4MDIwMTAwMjYwOVowGTEXMBUGA1UEAwwOdGVzdHNlcnZlci5jb20wggEiMA0G | ||
CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCxLgy9h8llkew2Bw09Alk7idMNbKE2 | ||
wSxIesCfA46oDrrzUI5LK0WR2Ad47uXPjoAikveV+r63uyHx1tMOV7FTTO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wuEShuhgHT66hn8XvfX | ||
Z2qqYHw4gX1Gbx7R+RsgeLMurEg= | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCxLgy9h8llkew2 | ||
Bw09Alk7idMNbKE2wSxIesCfA46oDrrzUI5LK0WR2Ad47uXPjoAikveV+r63uyHx | ||
1tMOV7FTTOtLuDPq669FShjcNA4TZFOhYEngbRsAsdxZyvyVNBDSchZ0B+5P0VTo | ||
JiCunWAWgV8JtuvAYTb0mGNzsVEclU9Y8RFX0gKMRO/4x0TugOlRtwlLOdQ29Xs+ | ||
+o30RrmijgvN9OX1osBtLHcRgp8OHkWrkl9m/HZ7w69OEUVUOpKBK6YRQYI/FK9t | ||
9uugMsWihzC0FLiDsedQYVdl5kur6yKZpc/+5hasP1GgbRBZYvCKXWqnPAwQdzto | ||
IZemOd8/AgMBAAECggEAGT7QfejtH1XNbF1Q25KMGFmpAs6pod2ga6th6sZc+0Eu | ||
DiE6RSejQAah+e9AO3S4eTSrpmkV56P4UDcl13NTRuU82YsjiqOOU7cdF7MrFkRD | ||
Tkkj/aBOKqktFnY/yxqiEvpCjMHciO7wxCs6mOa/nDVOz1mK+dxgMjXMZd2sCwBW | ||
cnlo3JB7fbSIS2US3kT+AOGaPoLaUHVizRu40+DfPtZMfwnk8EOtCZziHoF3cT6j | ||
ZD9BJS9T0ph4AJqxWOM+GQDS08wmaOE8add6aV5whBf0H8mP4GFFFhabDr2+N/t7 | ||
GZR9HbCZ79VDWKbggGA4cwlDv+LLBOGMKr784+J1oQKBgQDlsHAwZS7XG3uZrJpq | ||
+DfAaK5fAIWNtsXn5pS5rJOXUs1UI7oswxKAQZ/pMgkUSZBLhpAWW6J6hh/ysz1L | ||
mQk3szfGrRlM30CC2CxYQgum7ARGtlYYdi1H9kvXyBAmoBi8MvUkgB3QltEWE1Fk | ||
SZ1/3uDNPudGWXsILl2zagb/mQKBgQDFecrcugQpdii9p1HMqAwugaLCviVBv9nz | ||
qub0eeCOm7RYHWp7EjJ0xXVQUN+/AEMP8UlqiIPKq3JtrOccx2dVwOC9341PD61t | ||
zY5dnIaU6UVVkv/vxt2uOnSmyGrRDfftvyRJZmQOJT5VfO1dPKgxeLjn8cY+u6FR | ||
idb7dYN8lwKBgB/9uyKCdUuwoD5/M+LCP8Gk0uSYhgF++4GZNA3IY6Yn+kFF2KBz | ||
axhCC6vHNEyHEnnyfA8hJDg8hiafoGHvJsGDTLl3UpbKYYnX4hVI3aaaKN5Qdx1h | ||
GF11iIq9asJ2eft8fXhf/8cVunmAp014k19EA7uSj1PVErXI/3QFyIPBAoGACWLX | ||
lJQ23G2kVBde2PZn1dINlWoKRUzEJEPMRHSCiuS1trZ3ODBOO6SjBdVCPUba6SgT | ||
0D963Cg4ASSFu6VysO3BAOVeRxK8sIpjqOlmsC9CP2YESjZOlRhsMP03roYWcbNz | ||
GxYFzXJRuyh788GNUQSm7Uddn9+1NDX0BPG59TMCgYEAnvDoFszjrh+Qlnnmr8c/ | ||
fRMda8LGFqbHPRerLE7N0kRzJVeMhLs5hY8CaYUVp+0BxUgs56jCL4fw77u1u1iw | ||
2zGx2A0qBzK/heQvFKvK31WhZXj7lydOVW5p/CorO+nnFbqwy37KqHokb37Agbh+ | ||
f/vchbnflC+rie5eKlI2LtA= | ||
-----END PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use salvo::conn::rustls::{Keycert, RustlsConfig}; | ||
use salvo::prelude::*; | ||
|
||
#[handler] | ||
async fn hello() -> &'static str { | ||
"Hello World" | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
tracing_subscriber::fmt().init(); | ||
|
||
let router = Router::new().get(hello); | ||
let service = Service::new(router).hoop(ForceHttps::new().https_port(5443)); | ||
|
||
let config = RustlsConfig::new( | ||
Keycert::new() | ||
.cert(include_bytes!("../certs/cert.pem").as_ref()) | ||
.key(include_bytes!("../certs/key.pem").as_ref()), | ||
); | ||
let acceptor = TcpListener::new("0.0.0.0:5443") | ||
.rustls(config) | ||
.join(TcpListener::new("0.0.0.0:5800")) | ||
.bind() | ||
.await; | ||
Server::new(acceptor).serve(service).await; | ||
} |