Commit Graph
888 Commits
Author SHA1 Message Date
David Pedersen bf341fd034 Refactor all_the_tuples! macros (#1413) 2022-09-25 15:22:40 +02:00
David Pedersen 8dd9c8d286 Add missing changelog PR links 2022-09-25 14:41:15 +02:00
Jonas Platte 4847d681b1 Allow Routers to inherit state (#1368)
* Rename Fallback::Custom to Fallback::Service

* Allow Routers to inherit state

* Rename Router::{nest => nest_service} and add new nest method for Routers

* Fix lints

* Add basic tests for state inheritance

* Changelog
2022-09-25 11:56:23 +00:00
David PedersenandJonas Platte 2077d50021 Add map_request and friends (#1408)
* Add `map_request` and friends

* finish it

* changelog ref

* Apply suggestions from code review

Co-authored-by: Jonas Platte <[email protected]>

* address review feedback

* Apply suggestions from code review

Co-authored-by: Jonas Platte <[email protected]>

Co-authored-by: Jonas Platte <[email protected]>
2022-09-25 11:44:10 +00:00
Marek KuskowskiandDavid Pedersen 896ffc5fba Remove ContentLengthLimit (#1400)
* feat: remove ContentLengthLimit

* feat: remove ContentLengthLimit rejections

* fix: update multipart docs

* fix: typo

* feat: add wip extractor code

* feat: revert "feat: add wip extractor code"

* fix: update Multipart docs

* fix: update examples

* fix: missing import in an example

* fix: broken import yet again

* fix: disable default body limit for example

* fix: key value store example

* fix: update expected debug_handler output

* chore: update CHANGELOG

* Update axum/CHANGELOG.md

Co-authored-by: David Pedersen <[email protected]>
2022-09-24 11:29:53 +00:00
David Pedersen c3f3db79ec Support State with #[derive(FromRequest[Parts])] (#1391)
* Support `State` with `#[derive(FromRequest[Parts])]`

Fixes https://github.com/tokio-rs/axum/issues/1314

This makes it possible to extract things via `State` in
`#[derive(FromRequet)]`:

```rust
struct Foo {
    state: State<AppState>,
}
```

The state can also be inferred in a lot of cases so you only need to
write:

```rust
struct Foo {
    // since we're using `State<AppState>` we know the state has to be
    // `AppState`
    state: State<AppState>,
}
```

Same for

```rust
struct Foo {
    #[from_request(via(State))]
    state: AppState,
}
```

And

```rust
struct AppState {}
```

I think I've covered all the edge cases but there are (unsurprisingly) a
few.

* make sure things can be combined with other extractors

* main functions in ui tests don't need to be async

* Add test for multiple identicaly state types

* Add failing test for multiple states
2022-09-23 23:50:50 +02:00
Jonas Platte e3a17c1249 Add #[track_caller] attribute to Router::into_[make_]service (#1407) 2022-09-23 21:10:08 +02:00
Jonas Platte 4c846488c2 Update expected stderr of trybuild test (#1402) 2022-09-22 18:36:31 +02:00
Jonas Platte 69d64cecc3 Split RouterService off of Router (#1381) 2022-09-22 12:10:55 +02:00
Jonas Platte 18e3fac5d3 Small routing module refactoring (#1364) 2022-09-22 12:10:32 +02:00
David Pedersen 611c50ec8b Add middleware::from_extractor_with_state (#1396)
Fixes https://github.com/tokio-rs/axum/issues/1373
2022-09-20 10:13:06 +02:00
David Pedersen 112f5354ab Add example showing how to return anyhow::Errors (#1398) 2022-09-19 20:42:08 +00:00
David Pedersen de9909d955 Add DefaultBodyLimit::max to change the body size limit (#1397) 2022-09-19 22:41:54 +02:00
Jonas Platte 7105805ba2 Extend from_fn_with_state doctest (#1393) 2022-09-19 21:02:43 +02:00
Jonas Platte 4ade706ab0 Add track_caller to route_with_tsr (#1390)
… and route_service_with_tsr.
2022-09-18 23:12:08 +02:00
David Pedersen c93d7c324e Fix typo in docs 2022-09-18 22:24:11 +02:00
David Pedersen 21876fcc64 Clarify Clone requirements for using State (#1388) 2022-09-18 22:22:47 +02:00
David Pedersen c81549d95b Support streaming/chunked requests in ContentLengthLimit (#1389)
* Support streaming/chunked requests in `ContentLengthLimit`

* changelog
2022-09-18 20:21:38 +00:00
Siddhesh KanawadeandDavid Pedersen 015de21a52 feat: Add axum-casbin-auth and axum-middleware-example (#1357)
Co-authored-by: David Pedersen <[email protected]>
2022-09-18 21:34:13 +02:00
David Pedersen 8e52c5246f Use 400 Bad Request for FailedToDeserializeQueryString rejections (#1387)
* Use `400 Bad Request` for `FailedToDeserializeQueryString` rejections

Fixes https://github.com/tokio-rs/axum/issues/1378

From [the spec] about `422 Unprocessable Entity`:

> For example, this error condition may occur if an XML request body
> contains well-formed (i.e., syntactically correct), but semantically
> erroneous, XML instructions.

I understand this to mean that query params shouldn't use 422 because
that is about the request body.

So this changes `FailedToDeserializeQueryString` from `422 Unprocessable
Entity` to `400 Bad Request`.

[the spec]: https://datatracker.ietf.org/doc/html/rfc4918#section-11.2

* changelog
2022-09-18 21:32:47 +02:00
Ferenc Tamás 84f58ae9a5 expose FromRequest and FromRequestParts macros in axum (#1352) 2022-09-18 19:46:04 +02:00
Jonas Platte c09ecefcab Use regular non-exhaustive debug representation instead of custom one (#1380) 2022-09-16 22:56:25 +02:00
Jonas Platte c8dbe5a7e9 Relax Multipart FromRequest implementation bounds (#1379) 2022-09-16 18:49:42 +00:00
Hong Minhee (洪 民憙)andLee Dogeon 7476dd08cb Show the errored path on JsonDataError (#1371)
Previously, it was difficult to find out the path in the deep JSON tree at
which a deserialization error occurred.  This patch makes an error message
to contain the errored path.  In order to find out the path,
I added serde_path_to_error, a new optional dependency.

Co-authored-by: Lee Dogeon <[email protected]>

Co-authored-by: Lee Dogeon <[email protected]>
2022-09-13 17:52:16 +02:00
David Pedersen 2abda4de88 Port other proc-macros to new attribute parsing (#1372) 2022-09-12 21:26:10 +02:00
David Pedersen 8da69a98fc Refactor proc-macro attribute parsing (#1369)
* Refactor proc-macro attribute parsing

* Remove `#[allow(warnings)]` which was accidentally committed

* Change span for "cannot use `rejection` without `via`" error for enums

* fix test
2022-09-12 20:10:58 +02:00
David PedersenandJonas Platte 54d8439e35 Ship rc.2 (#1363)
* rc.2

* don't bump version of axum-macros

* fix

* Update axum/Cargo.toml

Co-authored-by: Jonas Platte <[email protected]>

* undo release of axum-extra

* fix

Co-authored-by: Jonas Platte <[email protected]>
axum-core-v0.3.0-rc.2 axum-v0.6.0-rc.2
2022-09-11 16:42:04 +02:00
David Pedersen 759e988747 Limit size of request bodies in Bytes extractor (#1346)
* Apply default limit to request body size

* Support disabling the default limit

* docs

* changelog
2022-09-10 06:36:30 +00:00
Fredrik Meringdal c6be977612 Fix docs for chained method routing (#1355) 2022-09-08 19:26:47 +00:00
Ferenc Tamás 6fc31e1888 Add aide and axum-jsonschema to ECOSYSTEM.md (#1360) 2022-09-08 18:30:41 +00:00
Jonas Platte da4ea4d4c2 Add must_use attribute to Redirect type (#1356) 2022-09-07 13:52:58 +02:00
sjud b5d4bf236e update ECOSYSTEM.md (#1345) 2022-09-03 15:54:25 +00:00
David Pedersen 4c9edb4cd4 Add middleware::{from_fn_with_state, from_fn_with_state_arc} (#1342) 2022-08-31 18:28:54 +00:00
David Pedersen 3f92f7d254 Improve opaque error message for Handler::layer (#1336) 2022-08-28 22:17:05 +02:00
valkyrie_pilot 805463c2ef Fix docs typo (#1334) 2022-08-27 08:01:23 +00:00
Chris GlassandDavid Pedersen b2ed55bd1f Added notes about extractor precedence (#1324)
* [doc] Added notes about extractor precedence

Both JSON and Form extractors consume the Body when they run, so they
need to be last in the order of extractors.
Added a note in the structs docs themselves pointing to the relevant
part of the documentation.

* Address review comments

- Added documentation snippet to  BodyStream, RawBody, Multipart
- Added documentation about the inner type of ContentLengthLimit
- Fixed link type in State

* Update axum/src/extract/content_length_limit.rs

Co-authored-by: David Pedersen <[email protected]>

* Cargo fmt didn't run for some reason

I need to check my editor config...

* Apply suggestions from code review

Co-authored-by: David Pedersen <[email protected]>

* Add targets to links

Co-authored-by: David Pedersen <[email protected]>
2022-08-26 13:02:04 +02:00
Liigo Zhuang f8683f37f8 Fix broken docs links (#1332) 2022-08-26 09:30:38 +00:00
David Pedersen eb6451c4fe Clarify Clone requirements even if using Router::with_state_arc (#1329) 2022-08-26 07:42:32 +00:00
David Pedersen eaabdb3973 Update out of date Router::nest docs (#1328) 2022-08-25 23:35:38 +02:00
David PedersenandJonas Platte 6d7c277700 Add example for parsing body based on Content-Type (#1320)
* Add example for parsing body based on `Content-Type`

* format

* Update examples/parse-body-based-on-content-type/src/main.rs

Co-authored-by: Jonas Platte <[email protected]>

* fix copy/paste errors

* rename type params

Co-authored-by: Jonas Platte <[email protected]>
2022-08-25 16:04:54 +02:00
Jonas Platte 92f6b68390 Panic when attempting to add a route_layer to an empty router (#1327) 2022-08-25 15:42:17 +02:00
Yann Simon 426b9f91e8 FromRequestParts does not have a 'B' type (#1315) 2022-08-24 09:56:02 +00:00
Chris GlassandDavid Pedersen d0b4c9032e Explicitely point out example's dependency (#1312)
* Explicitely point out example dependency

Save the next visitor to that docs page the trouble of having to figure
out why a Path<Uuid> extractor results in a cryptic error by default.

* Update axum/src/extract/path/mod.rs

Co-authored-by: David Pedersen <[email protected]>

Co-authored-by: David Pedersen <[email protected]>
2022-08-24 07:39:41 +00:00
David Pedersen 169e2f7c24 Mention FromRef, not From, in State docs (#1311) 2022-08-24 00:10:51 +02:00
David Pedersen b315b60bca Bump version of all crates (#1310)
* Bump version of all crates

* use the right versions inside the workspace
axum-extra-v0.4.0-rc.1 axum-macros-v0.3.0-rc.1 axum-core-v0.3.0-rc.1 axum-v0.6.0-rc.1
2022-08-23 22:57:13 +02:00
Jonas PlatteandDavid Pedersen 7705ef6661 Add #[derive(FromRequestParts)] (#1305)
* Add missing leading double colon

* Separate handling of last element in FromRequest derive

* FromRequestParts derive

* fix it and add lots of tests

* docs

* changelog

* Update axum-macros/src/lib.rs

Co-authored-by: Jonas Platte <[email protected]>

Co-authored-by: David Pedersen <[email protected]>
2022-08-23 19:14:02 +00:00
David Pedersen db08419a3b Tweak layer and route_layer docs (#1307) 2022-08-23 16:56:24 +00:00
David Pedersen 0e04260a27 Show path in panic message when merging overlapping MethodRouters (#1306) 2022-08-23 16:32:34 +02:00
David Pedersen fa51cf5266 Support turning any Service into a MakeService (#1302)
* Add `ServiceExt`

* changelog
2022-08-22 22:03:48 +02:00
David Pedersen ab36e65449 Add RequestExt and RequestPartsExt (#1301)
* Add `RequestExt` and `RequestPartsExt`

* don't double box futures

* changelog pr link
2022-08-22 18:34:46 +02:00