-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from portier/featNormalize
Expose normalization as endpoint & upgrade dependencies
- Loading branch information
Showing
15 changed files
with
378 additions
and
265 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# This file doubles as .gitignore and .dockerignore | ||
|
||
# Version control | ||
.git | ||
|
||
# Build products | ||
target | ||
lang/*.mo | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod auth; | ||
pub mod normalize; | ||
pub mod pages; |
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,33 @@ | ||
use email_address::EmailAddress; | ||
use futures::future; | ||
use http::{ContextHandle, HandlerResult}; | ||
use hyper::header::{CacheControl, CacheDirective, ContentType}; | ||
use hyper::server::Response; | ||
|
||
/// Request handler for the email normalization endpoint. | ||
/// | ||
/// Performs normalization of email addresses, for clients that cannot implement all the necessary | ||
/// parts of the relevant specifications. (Unicode, WHATWG, etc.) | ||
pub fn normalize(ctx_handle: &ContextHandle) -> HandlerResult { | ||
let ctx = ctx_handle.borrow(); | ||
|
||
let result = String::from_utf8_lossy(&ctx.body) | ||
.lines() | ||
.map(|s| { | ||
match s.parse::<EmailAddress>() { | ||
Ok(addr) => addr.to_string(), | ||
Err(_) => "".to_owned(), | ||
} | ||
}) | ||
.collect::<Vec<_>>() | ||
.join("\n"); | ||
|
||
let res = Response::new() | ||
.with_header(ContentType::plaintext()) | ||
.with_header(CacheControl(vec![ | ||
CacheDirective::NoCache, | ||
CacheDirective::NoStore, | ||
])) | ||
.with_body(result); | ||
Box::new(future::ok(res)) | ||
} |
Oops, something went wrong.