Better big form handling (#430)

* Allow customizing max form size from env vars

* Add error page for unprocessable entities

And change default http port to 7878

* Improve char counter: under the editor, more discrete, and give it a default value
This commit is contained in:
fdb-hiroshima
2019-01-27 10:55:22 +01:00
committed by GitHub
parent 06d6bd361a
commit e77e4d86e8
7 changed files with 103 additions and 21 deletions
+17 -2
View File
@@ -1,7 +1,8 @@
use atom_syndication::{ContentBuilder, Entry, EntryBuilder, LinkBuilder, Person, PersonBuilder};
use rocket::{
http::{RawStr, uri::{FromUriParam, Query}},
request::FromFormValue,
http::{RawStr, Status, uri::{FromUriParam, Query}},
Outcome,
request::{self, FromFormValue, FromRequest, Request},
response::NamedFile,
};
use std::path::{Path, PathBuf};
@@ -46,6 +47,20 @@ impl Page {
}
}
pub struct ContentLen(pub u64);
impl<'a, 'r> FromRequest<'a, 'r> for ContentLen {
type Error = ();
fn from_request(r: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
match r.limits().get("forms") {
Some(l) => Outcome::Success(ContentLen(l)),
None => Outcome::Failure((Status::InternalServerError, ())),
}
}
}
impl Default for Page {
fn default() -> Self {
Page(1)