Commit graph

1410 commits

Author SHA1 Message Date
David Pedersen
d7ba0b1d72
Relax bounds for FromExtractor (#1469)
Fixes #1467

We didn't actually use the bounds. I guess they were left over from a
previous version.
2022-10-10 16:39:16 +00:00
David Pedersen
70833b9f4f
Document differences between DefaultBodyLimit and RequestBodyLimit (#1461)
* Document differences between `DefaultBodyLimit` and `RequestBodyLimit`

* fix grammar

* fix accidental force push
2022-10-10 17:43:05 +02:00
David Pedersen
7420721f4d
Document RouterService (#1465)
Not sure what else there is to say :P

Fixes https://github.com/tokio-rs/axum/issues/1401
2022-10-10 00:23:11 +02:00
David Pedersen
b607ad5823
Improve map_response docs (#1464)
* Document when extractors run

* Document returning `impl IntoResponse`
2022-10-09 23:33:22 +02:00
David Pedersen
f9dc96fdce
Don't internally Arc the state (#1460) 2022-10-09 20:55:28 +00:00
Jonas Platte
a2ab338e68
Rewrite how state is passed from Router to MethodRouter 2022-10-09 19:33:40 +00:00
Jonas Platte
7cbacd1433
Improve the error message for state type inference failure in FromRequest(Parts) derive macro (#1432)
* Add a dedicated error message for state type inference issues

* Generate valid code even if state type can't be inferred

* Also error on state type inference for debug_handler
2022-10-09 20:25:05 +02:00
Valentin Brandl
ee0b71a4ac
Start second server on different port for metrics endpoint (#1444)
* Start second server on different port for metrics endpoint

* Don't track metrics on metrics server
2022-10-08 01:28:32 +02:00
Jonas Platte
a7d8954178
Use RequestPartsExt more in docs / examples (#1445)
* Use RequestPartsExt more in docs / examples

* Remove unused import
2022-10-04 17:26:51 +00:00
David Pedersen
a57bd9a118 Move changelog item to "unreleased" 2022-10-04 14:25:31 +02:00
Horu
a3c58a18ed
Fix typo in example (#1439) 2022-10-01 13:49:15 +00:00
Jonas Platte
b94248191e
Add RequestExt::{with_limited_body, into_limited_body} (#1420)
* Move RequestExt and RequestPartsExt into axum-core

* Add RequestExt::into_limited_body

… and use it for Bytes extraction.

* Add RequestExt::with_limited_body

… and use it for Multipart extraction.

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-09-28 20:20:47 +00:00
Marek Barvíř
be54583d98
Reexport key-expansion (#1425)
* Reexport key-expansion

* Description

Co-authored-by: Marek Barvíř <barvir@cadwork.cz>
2022-09-28 20:06:56 +00:00
Jonas Platte
410fd49aa9
Fix Cached<T> as the last argument of a handler function (#1428)
* Remove FromRequest impl for Cached<T>

* Add a test for Cached<T> as the last argument of a handler function
2022-09-28 09:06:15 +00:00
chuckberrypi
2c833ad276
rmv claim that state can't be passed to middleware (#1426)
axum::middleware::from_fn_with_state now allows middleware to access application state.
2022-09-27 22:19:59 +00:00
Danny
fef95bf37a
Add From impls for extract::ws::Message (#1421)
* Add From impls for extract::ws::Message

These come from tungstenite but were not exposed by axum

* Add changelog entry
2022-09-26 19:07:12 +00:00
David Schmitt
5a11ae8960
docs: add circleci-hook to ECOSYSTEM.md (#1422) 2022-09-26 18:41:49 +00:00
Jonas Platte
9196c09fe8
Merge handler::{WithState, IntoService} into one HandlerService type (#1418) 2022-09-26 14:51:42 +02:00
Logan Keenan
31638a2b22
Add tokio feature & make tokio optional for WASM support (#1382)
* add server feature and make tokio and hyper/server and tcp optional

* address review comments

* don't mention any specific runtimes in the example

* sort deps

* add `tokio` feature when adding `ws`

* don't always pull in tower feature that pulls in tokio io stuff

* remove usage of `tokio_cr`

* changelog

* depend on tokio version that supports wasm

* don't make it sound like tokio doesn't support wasm

* call out new default feature

Co-authored-by: Fisher Darling <fdarlingco@gmail.com>
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-09-25 15:10:33 +00:00
Jonas Platte
83ba8c3876
Remove *_boxed_response_body methods on MethodRouter (#1415)
They were identical to the methods without the prefix.
2022-09-25 16:26:18 +02:00
David Pedersen
04ef2f1bc0
Add map_response and friends (#1414)
* Add `map_response` and friends

* changelog
2022-09-25 16:21:30 +02:00
David Pedersen
0e4a894c16 Fix formatting of one more macro 2022-09-25 15:26:36 +02:00
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 Pedersen
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 <jplatte+git@posteo.de>

* address review feedback

* Apply suggestions from code review

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-09-25 11:44:10 +00:00
Marek Kuskowski
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 <david.pdrsn@gmail.com>
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 Kanawade
015de21a52
feat: Add axum-casbin-auth and axum-middleware-example (#1357)
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
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 (洪 民憙)
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 <dev.moreal@gmail.com>

Co-authored-by: Lee Dogeon <dev.moreal@gmail.com>
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 Pedersen
54d8439e35
Ship rc.2 (#1363)
* rc.2

* don't bump version of axum-macros

* fix

* Update axum/Cargo.toml

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

* undo release of axum-extra

* fix

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
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