Commit graph

67 commits

Author SHA1 Message Date
David Pedersen
b1f894a500 Fix unused import if compiling with default features 2022-11-18 00:22:11 +01:00
David Pedersen
e0ef641e5f
Rework Form and Query rejections (#1496)
* Change `FailedToDeserializeQueryString` rejection for `Form`

Its now called `FailedToDeserializeForm`.

* changelog

* Make dedicate rejection type for axum-extra's `Form`

* update trybuild test

* Make dedicate rejection type for axum-extra's `Query`
2022-11-08 20:31:06 +00:00
Jonas Platte
944f388ae0 Add missing cfg's for signed cookie tests 2022-11-05 11:33:27 +01:00
David Pedersen
f9dc96fdce
Don't internally Arc the state (#1460) 2022-10-09 20:55:28 +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
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
Jonas Platte
69d64cecc3
Split RouterService off of Router (#1381) 2022-09-22 12:10:55 +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
be624306f4
Only allow last extractor to mutate the request (#1272)
* Only allow last extractor to mutate the request

* Change `FromRequest` and add `FromRequestParts` trait (#1275)

* Add `Once`/`Mut` type parameter for `FromRequest` and `RequestParts`

* 🪄

* split traits

* `FromRequest` for tuples

* Remove `BodyAlreadyExtracted`

* don't need fully qualified path

* don't export `Once` and `Mut`

* remove temp tests

* depend on axum again

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

* Port `Handler` and most extractors (#1277)

* Port `Handler` and most extractors

* Put `M` inside `Handler` impls, not trait itself

* comment out tuples for now

* fix lints

* Reorder arguments to `Handler` (#1281)

I think `Request<B>, Arc<S>` is better since its consistent with
`FromRequest` and `FromRequestParts`.

* Port most things in axum-extra (#1282)

* Port `#[derive(TypedPath)]` and `#[debug_handler]` (#1283)

* port #[derive(TypedPath)]

* wip: #[debug_handler]

* fix #[debug_handler]

* don't need itertools

* also require `Send`

* update expected error

* support fully qualified `self`

* Implement FromRequest[Parts] for tuples (#1286)

* Port docs for axum and axum-core (#1285)

* Port axum-extra (#1287)

* Port axum-extra

* Update axum-core/Cargo.toml

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

* remove `impl FromRequest for Either*`

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

* New FromRequest[Parts] trait cleanup (#1288)

* Make private module truly private again

* Simplify tuple FromRequest implementation

* Port `#[derive(FromRequest)]` (#1289)

* fix tests

* fix docs

* revert examples

* fix docs link

* fix intra docs links

* Port examples (#1291)

* Document wrapping other extractors (#1292)

* axum-extra doesn't need to depend on axum-core (#1294)

Missed this in https://github.com/tokio-rs/axum/pull/1287

* Add `FromRequest` changes to changelogs (#1293)

* Update changelog

* Remove default type for `S` in `Handler`

* Clarify which types have default types for `S`

* Apply suggestions from code review

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

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

* remove unused import

* Rename `Mut` and `Once` (#1296)

* fix trybuild expected output

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-08-22 12:23:20 +02:00
David Pedersen
18dd830b84
Add #[non_exhaustive] to ProtoBufRejection (#1280) 2022-08-19 10:17:40 +00:00
David Pedersen
e7f1c88cd4
Always store state in an Arc (#1270)
* Add extension and state benchmarks

* wip

* Arc the state everywhere

* don't require `S: Clone`

* fix example
2022-08-17 20:08:24 +00:00
David Pedersen
423308de3c
Add type safe state extractor (#1155)
* begin threading the state through

* Pass state to extractors

* make state extractor work

* make sure nesting with different states work

* impl Service for MethodRouter<()>

* Fix some of axum-macro's tests

* Implement more traits for `State`

* Update examples to use `State`

* consistent naming of request body param

* swap type params

* Default the state param to ()

* fix docs references

* Docs and handler state refactoring

* docs clean ups

* more consistent naming

* when does MethodRouter implement Service?

* add missing docs

* use `Router`'s default state type param

* changelog

* don't use default type param for FromRequest and RequestParts

probably safer for library authors so you don't accidentally forget

* fix examples

* minor docs tweaks

* clarify how to convert handlers into services

* group methods in one impl block

* make sure merged `MethodRouter`s can access state

* fix docs link

* test merge with same state type

* Document how to access state from middleware

* Port cookie extractors to use state to extract keys (#1250)

* Updates ECOSYSTEM with a new sample project (#1252)

* Avoid unhelpful compiler suggestion (#1251)

* fix docs typo

* document how library authors should access state

* Add `RequestParts::with_state`

* fix example

* apply suggestions from review

* add relevant changes to axum-extra and axum-core changelogs

* Add `route_service_with_tsr`

* fix trybuild expectations

* make sure `SpaRouter` works with routers that have state

* Change order of type params on FromRequest and RequestParts

* reverse order of `RequestParts::with_state` args to match type params

* Add `FromRef` trait (#1268)

* Add `FromRef` trait

* Remove unnecessary type params

* format

* fix docs link

* format examples

* Avoid unnecessary `MethodRouter`

* apply suggestions from review

Co-authored-by: Dani Pardo <dani.pardo@inmensys.com>
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-08-17 15:13:31 +00:00
David Pedersen
90dbd52ee4
Fix lint warnings (#1267) 2022-08-17 09:41:52 +00:00
David Pedersen
f2243c4db0
Make WithRejection::into_inner public (#1266) 2022-08-17 08:59:16 +00:00
David Pedersen
e22f6f9d2b
Add Either{2..8} to axum-extra (#1263)
* Add `Either{2..8}`

* Apply suggestions from code review

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

* Either2 => Either

* Update axum-extra/src/either.rs

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

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-08-17 08:57:19 +00:00
Altair Bueno
fb21561616
Add WithRejection (#1262)
* new(axum-extra): Added `WithRejection` base impl

Based on @jplatte's version (https://github.com/tokio-rs/axum/issues/1116#issuecomment-1215048273), with slight changes

- Using `From<E::Rejection>` to define the trait bound on a more concise way
- Renamed variables to something more meaningfull

* revert(axum-extra): Removed `with_rejection` feat

* ref(axum-extra): Replaced `match` with `?`

* tests(axum-extra): Added test for `WithRejection`

* examples: Replaced custom `Json` extractor with `WithRejection`

* docs(axum-extra): Added doc to `WithRejection`

* fmt(cargo-check): removed whitespaces

* fmt(customize-extractor-error): missing fmt

* docs(axum-extra): doctest includes `Handler` test

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>

* docs(axum-extra):` _ `-> `rejection`

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>

* docs(axum-extra): fixed suggestions

* fix(axum-extra): `WithRejection` manual trait impl

* revert(customize-extractor-error): Undo example changes

refs: d878eede18 , f9200bf4b9

* example(customize-extractor-error): Added reference to `WithRejection`

* docs(axum-extra): Removed `customize-extractor-error` reference

* fmt(axum-extra): cargo fmt

* docs(axum-extra): Added `WithRejection` to CHANGELOG.md

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-08-17 07:59:25 +00:00
David Pedersen
01630cfef6
Add sync constructors to CookieJar, SignedCookieJar, and PrivateCookieJar (#1264)
* Add sync constructors to `CookieJar`, `SignedCookieJar`, and `PrivateCookieJar`

* Move to constructor

* use `RequestParts::extract`
2022-08-16 15:42:01 +02:00
David Pedersen
50a4be999d
Update matchit and fix nesting inconsistencies (#1086)
* Break `Router::nest` into `nest` and `nest_service` methods

* fix doc tests

* update docs

* fix

* Only accept `Router` in `Resource::{nest, nest_collection}`

* update changelog

* fix docs

* fix `MatchedPath` with `Router`s nested with `nest_service`

* Apply suggestions from code review

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

* adjust docs for fallbacks

* Always nest services as opaque

* fix old docs reference

* more tests for `MatchedPath` with nested handlers

* minor clean up

* use identifier captures in format strings

* Apply suggestions from code review

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

* fix test

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-08-11 10:17:08 +00:00
Filip Kieres
7faf059234
Document browsers ignoring SSE events without data fields (#1242) (#1214) 2022-08-10 17:14:42 +02:00
David Pedersen
e79820dbc4
Support chaining handlers with one.or(two).or(three) (#1170)
* WIP: Handler fallbacks

* Docs

* box futures a bit less

* changelog
2022-08-10 10:09:08 +00:00
Jonas Platte
7cbb7cf135
Use new Cargo features to avoid implicit features for optional dependencies (#1239)
* Fix changelog entry for MSRV change in axum-extra 0.3.5

* Bump MSRV to 1.60 for axum, axum-extra, axum-macros

* Use new Cargo features to avoid implicit features for optional dependencies
2022-08-09 18:43:02 +02:00
Jonas Platte
e6fb53fd68
Fix a typo in axum_extra::extract::Query docs (#1201) 2022-07-27 16:32:21 +02:00
David Pedersen
10ab8c7aba
Add missing cfg to axum_extra::extract::Form (#1194) 2022-07-26 00:25:45 +02:00
David Pedersen
b243e171fd
Accept S::Response: IntoResponse everywhere (#1165) 2022-07-19 18:55:15 +02:00
SzudemJ
73041c8988
Avoid exposure of type names by QueryRejection (#1171) 2022-07-18 13:43:18 +00:00
David Pedersen
8c9998eab7
Don't derive debug impl for Resource (#1153)
We don't actually require `B` to be `Debug` but the derived impl does.
2022-07-11 09:41:41 +02:00
David Pedersen
a4c820420d
Remove trailing slash redirects (#1119)
* Prepare axum-next branch

* Remove deprecated `extractor_middleware` function (#1077)

* Allow `Error: Into<Infallible>` for `Route::{layer, route_layer}` (#948)

* Allow `Error: Into<Infallible>` for `Route::{layer, route_layer}` (#924)

* Allow `Error: Into<Infallible>` for `Route::{layer, route_layer}`

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

* changelog

* fixup changelog

* Panic on overlapping routes in `MethodRouter` (#1102)

* Panic on overlapping routes in `MethodRouter`

* changelog link

* add test to ensure `head` and `get` don't overlap

* Fix changelog

* Prepare axum-next branch

* Remove trailing slash redirects

* changelog link

* Fix changelog

* remove asserting to make make the test more clear

* remove tsr related feature

* Add `RouterExt::route_with_tsr`

* Apply suggestions from code review

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

* Update axum-extra/src/routing/mod.rs

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

* fix typos in docs

* Update axum/CHANGELOG.md

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

* mention `RouterExt::route_with_tsr` in the changelog

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-06-30 00:22:43 +02:00
David Pedersen
6b6a415622
Add JsonLines extractor and response (#1093) 2022-06-20 20:49:18 +02:00
David Pedersen
453202b490
Document all cargo features (#1079) 2022-06-10 08:46:09 +02:00
David Pedersen
73b1bafbf8
Add AsyncReadBody (#1072)
* Add `AsyncReadBody`

* changelog

* sort cargo.toml
2022-06-08 11:02:42 +02:00
David Pedersen
19fe93262f
Use impl IntoResponse less in docs (#1049) 2022-05-22 13:41:29 +02:00
David Pedersen
5948cde6c1
Support customizing rejections for #[derive(TypedPath)] (#1012)
* Support customizing rejections for `#[derive(TypedPath)]`

* changelog

* clean up
2022-05-17 21:36:05 +02:00
Jonas Platte
b215a87a19
Add axum_extra::extract::Query 2022-05-17 20:19:24 +02:00
David Pedersen
178e1801e9
Add axum_extra::extract::Form (#1031)
* Add `axum_extra::extra::Form`

* update tokio-util ban
2022-05-15 15:17:45 +00:00
David Pedersen
4ff78e552d
Support Option and Result in typed paths (#1001)
* Support `Option` and `Result` in typed paths

* changelog

* Update axum-extra/CHANGELOG.md

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

* fix one more

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-05-06 09:42:10 +02:00
David Pedersen
700617963f
Move private and signed cookies behind feature flags (#949)
* move signed cookies into their own module

* Require features for private/signed cookies

* enable "cookie" feature when enabling private/signed cookies

* add `#[cfg]`s in a few more places
2022-04-27 10:11:16 +02:00
David Pedersen
405e3f8c44
Add SpaRouter (#904) 2022-04-03 18:29:37 +02:00
David Pedersen
01a4c88d7a
Add PrivateCookieJar (#900) 2022-04-01 16:37:55 +02:00
David Pedersen
da3ca22301
Fix SignedCookieJar with custom key type (#899) 2022-04-01 11:40:42 +02:00
Paolo Barbolini
1b4c54c6e6
axum-extra: re-export the Expiration and SameSite structs from the cookie crate (#898) 2022-04-01 10:46:43 +02:00
Evan Schwartz
3084dc10ca
Accept &str for Redirect (#889)
* Accept &str for Redirect

* Fix doc example

* fix more docs examples

* update changelog

* fix changelog label

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-03-31 10:03:06 +02:00
Jonas Platte
80753f8f5c
Remove unnecessary mut from (Signed)CookieJar examples (#850) 2022-03-10 12:53:51 +01:00
David Pedersen
f045f2356c
Add cookie management to axum-extra (#816)
* Cookie management

* fix feature

* Update axum-extra/src/extract/cookie.rs

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

* add tests

* Apply suggestions from code review

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

* less convoluted wording

* changelog

* Make the jars themselves implement `IntoResponseParts`

* dedup tests

* fix docs

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-03-04 10:53:36 +01:00
David Pedersen
d943ba6d81
Replace HasRoutes with Into<Router> (#819)
* Move `HasRoutes` into axum

* fix doc test

* Just use `Into<Router>`
2022-03-03 21:50:31 +00:00
David Pedersen
bad3abb960 Remove out of date docs
These accidentally weren't removed in https://github.com/tokio-rs/axum/pull/790
2022-03-01 14:09:30 +01:00
David Pedersen
f12ab072c5
Add IntoResponseParts (#797)
* Add `IntoResponseParts`

* docs

* Add test

* don't allow overriding body or response

* macroify impls

* re-order things a bit

* Fix tests

* Also allow overriding version

* Move things into separate modules

* docs

* clean up

* fix trybuild test

* remove churn

* simplify buliding response

* fixup test

* fix docs typo

* Use `HeaderValue::from_static`, might be faster

* Bring back `impl IntoResponse` in example

* Remove blanket impl to improve error message

* don't need to set `content-type`

* Apply suggestions from code review

Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>

* changelog

Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>
2022-02-28 23:04:33 +00:00
David Pedersen
da74084146
Easily convert typed paths into URIs (#790)
* Easily convert typed paths into URIs

`#[derive(TypedPath)]` will now also generate `TryFrom<_> for Uri` for
easily converting paths into URIs for use with `Redirect` and friends.

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

* Use a method on the `TypedPath` trait to convert to `Uri`

* fix doc ref

* Update changelogs
2022-02-28 09:58:22 +01:00
David Pedersen
7a228a584b
Type safe routing (#756)
* wip

* wip

* make macro implement trait

* checkpoint

* checkpoint

* Simplify things quite a bit

* re-export `axum_macros::TypedPath` from `axum_extra`

* docs

* add missing feature

* fix docs link

* fix features

* fix missing imports

* make serde an optional dep again

* ui tests

* Break things up a bit

* Update span for `FromRequest` impls to point to callsite

* make docs feature labels show up automatically

* Apply suggestions from code review

Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>

* add note about Display/Serialize being compatible

* Update axum-extra/src/routing/typed.rs

Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>

* fix missing docs link

* what about typed methods?

* Revert "what about typed methods?"

This reverts commit cc1f989467.

* don't allow wildcards for now

* percent encode params

* Update axum-extra/src/routing/typed.rs

Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>

* rephrase args

* changelog

Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>
2022-02-18 14:13:56 +01:00
David Pedersen
515495d957
Set content-length for responses to HEAD requests (#734)
* Set `content-length` internally in `Router`

* changelog

* require `B: HttpBody` at the `impl`

* add changelog refs
2022-01-31 13:48:51 +01:00