Merge branch 'doc-into-req' into user-management

This commit is contained in:
Emi Tatsuo 2020-11-21 17:19:49 -05:00
commit 115d0aa120
Signed by: Emi
GPG Key ID: 68FAB2E2E6DFC98B
4 changed files with 25 additions and 15 deletions

View File

@ -7,13 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Added ### Added
- `document` API for creating Gemini documents - `document` API for creating Gemini documents
- preliminary timeout API, incl a special case for complex MIMEs by [@Alch-Emi](https://github.com/Alch-Emi) - preliminary timeout API, incl a special case for complex MIMEs by [@Alch-Emi]
- `Response::success_with_body` by [@Alch-Emi](https://github.com/Alch-Emi) - `Response::success_with_body` by [@Alch-Emi]
- `redirect_temporary_lossy` for `Response` and `ResponseHeader` - `redirect_temporary_lossy` for `Response` and `ResponseHeader`
- `bad_request_lossy` for `Response` and `ResponseHeader` - `bad_request_lossy` for `Response` and `ResponseHeader`
- support for a lot more mime-types in `guess_mime_from_path`, backed by the `mime_guess` crate - support for a lot more mime-types in `guess_mime_from_path`, backed by the `mime_guess` crate
- customizable TLS cert & key paths by [@Alch-Emi](https://github.com/Alch-Emi) - customizable TLS cert & key paths by [@Alch-Emi]
- `server_dir` default feature for serve_dir utils [@Alch-Emi](https://github.com/Alch-Emi) - `server_dir` default feature for serve_dir utils [@Alch-Emi]
- Docments can be converted into responses with std::convert::Into [@Alch-Emi]
### Improved ### Improved
- build time and size by [@Alch-Emi](https://github.com/Alch-Emi) - build time and size by [@Alch-Emi](https://github.com/Alch-Emi)
### Changed ### Changed
@ -37,4 +38,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.2.0] - 2020-11-14 ## [0.2.0] - 2020-11-14
### Added ### Added
- Access to client certificates by [@Alch-Emi](https://github.com/Alch-Emi) - Access to client certificates by [@Alch-Emi]
[@Alch-Emi]: https://github.com/Alch-Emi

View File

@ -16,9 +16,7 @@ async fn main() -> Result<()> {
} }
async fn handle_request(_request: Request) -> Result<Response> { async fn handle_request(_request: Request) -> Result<Response> {
let mut document = Document::new(); let response = Document::new()
document
.add_preformatted(include_str!("northstar_logo.txt")) .add_preformatted(include_str!("northstar_logo.txt"))
.add_blank_line() .add_blank_line()
.add_link("https://docs.rs/northstar", "Documentation") .add_link("https://docs.rs/northstar", "Documentation")
@ -41,7 +39,7 @@ async fn handle_request(_request: Request) -> Result<Response> {
.add_preformatted_with_alt("sh", concat!( .add_preformatted_with_alt("sh", concat!(
"mkdir cert && cd cert\n", "mkdir cert && cd cert\n",
"openssl req -x509 -nodes -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365", "openssl req -x509 -nodes -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365",
)); ))
.into();
Ok(Response::document(document)) Ok(response)
} }

View File

@ -2,6 +2,8 @@ use tokio::io::AsyncRead;
#[cfg(feature="serve_dir")] #[cfg(feature="serve_dir")]
use tokio::fs::File; use tokio::fs::File;
use std::borrow::Borrow;
use crate::types::Document; use crate::types::Document;
pub enum Body { pub enum Body {
@ -9,9 +11,9 @@ pub enum Body {
Reader(Box<dyn AsyncRead + Send + Sync + Unpin>), Reader(Box<dyn AsyncRead + Send + Sync + Unpin>),
} }
impl From<Document> for Body { impl<D: Borrow<Document>> From<D> for Body {
fn from(document: Document) -> Self { fn from(document: D) -> Self {
Self::from(document.to_string()) Self::from(document.borrow().to_string())
} }
} }

View File

@ -1,4 +1,5 @@
use std::convert::TryInto; use std::convert::TryInto;
use std::borrow::Borrow;
use anyhow::*; use anyhow::*;
use uriparse::URIReference; use uriparse::URIReference;
@ -19,7 +20,7 @@ impl Response {
} }
} }
pub fn document(document: Document) -> Self { pub fn document(document: impl Borrow<Document>) -> Self {
Self::success_with_body(&GEMINI_MIME, document) Self::success_with_body(&GEMINI_MIME, document)
} }
@ -94,3 +95,9 @@ impl Response {
self.body.take() self.body.take()
} }
} }
impl<D: Borrow<Document>> From<D> for Response {
fn from(doc: D) -> Self {
Self::document(doc)
}
}