Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update max request size #64

Merged
merged 5 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions dropshot/examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ async fn main() -> Result<(), String> {
* request port 0, which allows the operating system to pick any available
* port.
*/
let config_dropshot = ConfigDropshot {
bind_address: "127.0.0.1:0".parse().unwrap(),
};
let config_dropshot: ConfigDropshot = Default::default();

/*
* For simplicity, we'll configure an "info"-level logger that writes to
Expand Down
1 change: 1 addition & 0 deletions dropshot/examples/pagination-basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ async fn main() -> Result<(), String> {
let ctx = Arc::new(tree);
let config_dropshot = ConfigDropshot {
bind_address: SocketAddr::from((Ipv4Addr::LOCALHOST, port)),
request_body_max_bytes: 1024,
};
let config_logging = ConfigLogging::StderrTerminal {
level: ConfigLoggingLevel::Debug,
Expand Down
1 change: 1 addition & 0 deletions dropshot/examples/pagination-multiple-resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ async fn main() -> Result<(), String> {
let ctx = Arc::new(DataCollection::new());
let config_dropshot = ConfigDropshot {
bind_address: SocketAddr::from((Ipv4Addr::LOCALHOST, port)),
request_body_max_bytes: 1024,
};
let config_logging = ConfigLogging::StderrTerminal {
level: ConfigLoggingLevel::Debug,
Expand Down
1 change: 1 addition & 0 deletions dropshot/examples/pagination-multiple-sorts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ async fn main() -> Result<(), String> {
let ctx = Arc::new(ProjectCollection::new());
let config_dropshot = ConfigDropshot {
bind_address: SocketAddr::from((Ipv4Addr::LOCALHOST, port)),
request_body_max_bytes: 1024,
};
let config_logging = ConfigLogging::StderrTerminal {
level: ConfigLoggingLevel::Debug,
Expand Down
12 changes: 12 additions & 0 deletions dropshot/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use std::net::SocketAddr;
* r##"
* [http_api_server]
* bind_address = "127.0.0.1:12345"
* request_body_max_bytes = 1024
*
* ## ... (other app-specific config)
* "##
Expand All @@ -45,4 +46,15 @@ use std::net::SocketAddr;
pub struct ConfigDropshot {
/** IP address and TCP port to which to bind for accepting connections */
pub bind_address: SocketAddr,
/** maximum allowed size of a request body, defaults to 1024 */
pub request_body_max_bytes: usize,
}

impl Default for ConfigDropshot {
fn default() -> Self {
ConfigDropshot {
bind_address: "127.0.0.1:0".parse().unwrap(),
request_body_max_bytes: 1024,
}
}
}
1 change: 1 addition & 0 deletions dropshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
* HttpServer::new(
* &ConfigDropshot {
* bind_address: "127.0.0.1:0".parse().unwrap(),
* request_body_max_bytes: 1024,
* },
* api,
* Arc::new(()),
Expand Down
2 changes: 2 additions & 0 deletions dropshot/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ impl PathSegment {
if segment.starts_with('{') || segment.ends_with('}') {
assert!(
segment.starts_with('{'),
"{}",
"HTTP URI path segment variable missing leading \"{\""
);
assert!(
segment.ends_with('}'),
"{}",
"HTTP URI path segment variable missing trailing \"}\""
);
assert!(
Expand Down
2 changes: 1 addition & 1 deletion dropshot/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl HttpServer {
private,
config: ServerConfig {
/* We start aggressively to ensure test coverage. */
request_body_max_bytes: 1024,
request_body_max_bytes: config.request_body_max_bytes,
page_max_nitems: NonZeroUsize::new(10000).unwrap(),
page_default_nitems: NonZeroUsize::new(100).unwrap(),
},
Expand Down
4 changes: 1 addition & 3 deletions dropshot/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ pub fn test_setup(test_name: &str, api: ApiDescription) -> TestContext {
* multiple concurrent tests, so any fixed port could result in spurious
* failures due to port conflicts.
*/
let config_dropshot = ConfigDropshot {
bind_address: "127.0.0.1:0".parse().unwrap(),
};
let config_dropshot: ConfigDropshot = Default::default();

let config_logging = ConfigLogging::File {
level: ConfigLoggingLevel::Debug,
Expand Down
6 changes: 3 additions & 3 deletions dropshot/tests/fail/bad_endpoint1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ error: incompatible function signature; expected async fn (Arc<RequestContext>(,
11 | async fn bad_endpoint() -> Result<HttpResponseOk<()>, HttpError> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `fn() -> impl std::future::Future {<impl std::convert::From<bad_endpoint> for dropshot::ApiEndpoint>::from::bad_endpoint}: dropshot::handler::HttpHandlerFunc<_, _>` is not satisfied
error[E0277]: the trait bound `fn() -> impl Future {<impl From<bad_endpoint> for ApiEndpoint>::from::bad_endpoint}: dropshot::handler::HttpHandlerFunc<_, _>` is not satisfied
--> $DIR/bad_endpoint1.rs:11:10
|
11 | async fn bad_endpoint() -> Result<HttpResponseOk<()>, HttpError> {
| ^^^^^^^^^^^^ the trait `dropshot::handler::HttpHandlerFunc<_, _>` is not implemented for `fn() -> impl std::future::Future {<impl std::convert::From<bad_endpoint> for dropshot::ApiEndpoint>::from::bad_endpoint}`
| ^^^^^^^^^^^^ the trait `dropshot::handler::HttpHandlerFunc<_, _>` is not implemented for `fn() -> impl Future {<impl From<bad_endpoint> for ApiEndpoint>::from::bad_endpoint}`
|
::: $WORKSPACE/dropshot/src/api_description.rs
|
| HandlerType: HttpHandlerFunc<FuncParams, ResponseType>,
| ----------------------------------------- required by this bound in `dropshot::ApiEndpoint::new`
| ----------------------------------------- required by this bound in `ApiEndpoint::new`
12 changes: 6 additions & 6 deletions dropshot/tests/fail/bad_endpoint3.stderr
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
error[E0277]: the trait bound `std::string::String: dropshot::Extractor` is not satisfied
error[E0277]: the trait bound `String: Extractor` is not satisfied
--> $DIR/bad_endpoint3.rs:15:12
|
9 | / #[endpoint {
10 | | method = GET,
11 | | path = "/test",
12 | | }]
| |__- required by this bound in `_::{{closure}}#0::need_extractor`
| |__- required by this bound in `need_extractor`
...
15 | param: String,
| ^^^^^^
| |
| the trait `dropshot::Extractor` is not implemented for `std::string::String`
| the trait `Extractor` is not implemented for `String`
| required by a bound in this

error[E0277]: the trait bound `fn(std::sync::Arc<dropshot::RequestContext>, std::string::String) -> impl std::future::Future {<impl std::convert::From<bad_endpoint> for dropshot::ApiEndpoint>::from::bad_endpoint}: dropshot::handler::HttpHandlerFunc<_, _>` is not satisfied
error[E0277]: the trait bound `fn(Arc<RequestContext>, String) -> impl Future {<impl From<bad_endpoint> for ApiEndpoint>::from::bad_endpoint}: dropshot::handler::HttpHandlerFunc<_, _>` is not satisfied
--> $DIR/bad_endpoint3.rs:13:10
|
13 | async fn bad_endpoint(
| ^^^^^^^^^^^^ the trait `dropshot::handler::HttpHandlerFunc<_, _>` is not implemented for `fn(std::sync::Arc<dropshot::RequestContext>, std::string::String) -> impl std::future::Future {<impl std::convert::From<bad_endpoint> for dropshot::ApiEndpoint>::from::bad_endpoint}`
| ^^^^^^^^^^^^ the trait `dropshot::handler::HttpHandlerFunc<_, _>` is not implemented for `fn(Arc<RequestContext>, String) -> impl Future {<impl From<bad_endpoint> for ApiEndpoint>::from::bad_endpoint}`
|
::: $WORKSPACE/dropshot/src/api_description.rs
|
| HandlerType: HttpHandlerFunc<FuncParams, ResponseType>,
| ----------------------------------------- required by this bound in `dropshot::ApiEndpoint::new`
| ----------------------------------------- required by this bound in `ApiEndpoint::new`
8 changes: 4 additions & 4 deletions dropshot/tests/fail/bad_endpoint6.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ error[E0277]: the trait bound `Ret: serde::ser::Serialize` is not satisfied
20 | | }]
| |__^ the trait `serde::ser::Serialize` is not implemented for `Ret`
|
= note: required by `dropshot::HttpResponseOk`
= note: required by `HttpResponseOk`

error[E0277]: the trait bound `fn(std::sync::Arc<dropshot::RequestContext>) -> impl std::future::Future {<impl std::convert::From<bad_endpoint> for dropshot::ApiEndpoint>::from::bad_endpoint}: dropshot::handler::HttpHandlerFunc<_, _>` is not satisfied
error[E0277]: the trait bound `fn(Arc<RequestContext>) -> impl Future {<impl From<bad_endpoint> for ApiEndpoint>::from::bad_endpoint}: dropshot::handler::HttpHandlerFunc<_, _>` is not satisfied
--> $DIR/bad_endpoint6.rs:17:1
|
17 | / #[endpoint {
18 | | method = GET,
19 | | path = "/test",
20 | | }]
| |__^ the trait `dropshot::handler::HttpHandlerFunc<_, _>` is not implemented for `fn(std::sync::Arc<dropshot::RequestContext>) -> impl std::future::Future {<impl std::convert::From<bad_endpoint> for dropshot::ApiEndpoint>::from::bad_endpoint}`
| |__^ the trait `dropshot::handler::HttpHandlerFunc<_, _>` is not implemented for `fn(Arc<RequestContext>) -> impl Future {<impl From<bad_endpoint> for ApiEndpoint>::from::bad_endpoint}`
|
::: $WORKSPACE/dropshot/src/api_description.rs
|
| HandlerType: HttpHandlerFunc<FuncParams, ResponseType>,
| ----------------------------------------- required by this bound in `dropshot::ApiEndpoint::new`
| ----------------------------------------- required by this bound in `ApiEndpoint::new`
14 changes: 7 additions & 7 deletions dropshot/tests/fail/bad_endpoint7.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ error[E0277]: the trait bound `Ret: serde::ser::Serialize` is not satisfied
27 | | }))
| |_____^ the trait `serde::ser::Serialize` is not implemented for `Ret`
|
= note: required by `dropshot::HttpResponseOk`
= note: required by `HttpResponseOk`

error[E0277]: the trait bound `Ret: serde::ser::Serialize` is not satisfied
--> $DIR/bad_endpoint7.rs:24:8
Expand All @@ -23,7 +23,7 @@ error[E0277]: the trait bound `Ret: serde::ser::Serialize` is not satisfied
::: $WORKSPACE/dropshot/src/handler.rs
|
| pub struct HttpResponseOk<T: JsonSchema + Serialize + Send + Sync + 'static>(
| --------- required by this bound in `dropshot::HttpResponseOk`
| --------- required by this bound in `HttpResponseOk`

error[E0277]: the trait bound `Ret: serde::ser::Serialize` is not satisfied
--> $DIR/bad_endpoint7.rs:24:5
Expand All @@ -37,7 +37,7 @@ error[E0277]: the trait bound `Ret: serde::ser::Serialize` is not satisfied
::: $WORKSPACE/dropshot/src/handler.rs
|
| pub struct HttpResponseOk<T: JsonSchema + Serialize + Send + Sync + 'static>(
| --------- required by this bound in `dropshot::HttpResponseOk`
| --------- required by this bound in `HttpResponseOk`

error[E0277]: the trait bound `Ret: serde::ser::Serialize` is not satisfied
--> $DIR/bad_endpoint7.rs:23:45
Expand All @@ -54,15 +54,15 @@ error[E0277]: the trait bound `Ret: serde::ser::Serialize` is not satisfied
::: $WORKSPACE/dropshot/src/handler.rs
|
| pub struct HttpResponseOk<T: JsonSchema + Serialize + Send + Sync + 'static>(
| --------- required by this bound in `dropshot::HttpResponseOk`
| --------- required by this bound in `HttpResponseOk`

error[E0277]: the trait bound `fn(std::sync::Arc<dropshot::RequestContext>) -> impl std::future::Future {<impl std::convert::From<bad_endpoint> for dropshot::ApiEndpoint>::from::bad_endpoint}: dropshot::handler::HttpHandlerFunc<_, _>` is not satisfied
error[E0277]: the trait bound `fn(Arc<RequestContext>) -> impl Future {<impl From<bad_endpoint> for ApiEndpoint>::from::bad_endpoint}: dropshot::handler::HttpHandlerFunc<_, _>` is not satisfied
--> $DIR/bad_endpoint7.rs:21:10
|
21 | async fn bad_endpoint(
| ^^^^^^^^^^^^ the trait `dropshot::handler::HttpHandlerFunc<_, _>` is not implemented for `fn(std::sync::Arc<dropshot::RequestContext>) -> impl std::future::Future {<impl std::convert::From<bad_endpoint> for dropshot::ApiEndpoint>::from::bad_endpoint}`
| ^^^^^^^^^^^^ the trait `dropshot::handler::HttpHandlerFunc<_, _>` is not implemented for `fn(Arc<RequestContext>) -> impl Future {<impl From<bad_endpoint> for ApiEndpoint>::from::bad_endpoint}`
|
::: $WORKSPACE/dropshot/src/api_description.rs
|
| HandlerType: HttpHandlerFunc<FuncParams, ResponseType>,
| ----------------------------------------- required by this bound in `dropshot::ApiEndpoint::new`
| ----------------------------------------- required by this bound in `ApiEndpoint::new`
13 changes: 9 additions & 4 deletions dropshot/tests/test_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ async fn test_config_bind_address() {
* don't want to depend on too much from the ApiServer here -- but we
* should have successfully made the request.)
*/
let config_text =
format!("bind_address = \"{}:{}\"\n", bind_ip_str, bind_port);
let config_text = format!(
"bind_address = \"{}:{}\"\nrequest_body_max_bytes = 1024",
bind_ip_str, bind_port
);
let config =
read_config::<ConfigDropshot>("bind_address", &config_text).unwrap();
let mut server = make_server(&config, &log);
Expand All @@ -138,8 +140,11 @@ async fn test_config_bind_address() {
* Start a server on another TCP port and make sure we can reach that
* one (and NOT the one we just shut down).
*/
let config_text =
format!("bind_address = \"{}:{}\"\n", bind_ip_str, bind_port + 1,);
let config_text = format!(
"bind_address = \"{}:{}\"\nrequest_body_max_bytes = 1024",
bind_ip_str,
bind_port + 1,
);
let config =
read_config::<ConfigDropshot>("bind_address", &config_text).unwrap();
let mut server = make_server(&config, &log);
Expand Down