Commit Graph
182 Commits
Author SHA1 Message Date
Jonas PlatteandGitHub 1812c4dfe8 Remove explicit TryFrom, TryInto imports (#1099) 2022-06-17 18:36:49 +00:00
David PedersenandGitHub 93251fa203 Bump MSRV to 1.56 and update to the 2021 edition (#1098) 2022-06-17 20:11:35 +02:00
fd70f81c46 More robust asset paths in examples (#1090)
* More robust asset paths in examples

* Update examples/low-level-rustls/src/main.rs

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

* format

Co-authored-by: Jonas Platte <[email protected]>
2022-06-15 22:42:49 +02:00
cbb2e8a244 Fix missing assets in websockets example (#1089)
* fix missing assets running websockets example

* Update examples/websockets/src/main.rs

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

* remove unnecessary mut

* fix cargo fmt

Co-authored-by: David Pedersen <[email protected]>
2022-06-15 10:04:44 +02:00
David PedersenandGitHub 968ee44631 Sort dependencies in Cargo.tomls (#1076)
* sort dependencies

* check sorted deps on CI

* this should fail

* does caching matter?

* fix sorting
2022-06-10 08:59:17 +02:00
David PedersenandGitHub be71e7b286 Fix vulnerability in example-stream-to-file example (#1040)
* Fix vulnerability in example-stream-to-file example

* Save files to separate directory
2022-05-17 12:38:15 +02:00
Jonas PlatteandGitHub 591434778f Slightly simplify CORS example (#1027) 2022-05-12 11:36:57 +02:00
David PedersenandGitHub 7774cfd1f7 Update static file server example (#1011) 2022-05-08 19:52:34 +00:00
takumiandGitHub 4b384fa01c upgrade uuid from 0.8 to 1.0 (#995) 2022-05-05 07:48:49 +02:00
David PedersenandGitHub d1043db254 Fix driving readiness for example-rest-grpc-multiplex (#988) 2022-05-03 09:21:49 +00:00
4ff5e409e3 Add rest and grpc example (#967)
* Add rest and grpc example

* remove needless dependencies

* Apply suggestions from code review

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

* Update examples/rest-grpc-multiplex/src/main.rs

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

* Update examples/rest-grpc-multiplex/src/main.rs

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

* Update examples/rest-grpc-multiplex/src/multiplex_service.rs

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

* Update examples/rest-grpc-multiplex/Cargo.toml

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

* Update examples/rest-grpc-multiplex/src/multiplex_service.rs

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

* clean noisy code

* fix nitpicks

* missing newline

Co-authored-by: David Pedersen <[email protected]>
2022-05-02 15:52:55 +00:00
David PedersenandGitHub 1fe4558362 Move examples to separate workspace (#978)
* Move examples to separate workspace

* update commands to run examples

* remove debug
2022-04-29 18:53:41 +02:00
David PedersenandGitHub 79f6cde3b1 Update to tower-http 0.3.0 (#965)
* Update to tower-http 0.3.0

* changelog link
2022-04-25 14:59:16 +00:00
SlavaandGitHub 0313c08dc9 helpful note about posting with CORS (#938) 2022-04-17 08:13:22 +00:00
a237edb7c3 Fix example-unix-domain-socket on non-unix platforms (#919)
* remove unused `axum`'s dependency:`tokio-util`

* fix `examples/todos`'s `async fn todos_index` iter_overeager_cloned

* Add docs to `/examples/async-graphql`, just like other xamples.

* remove `examples/async-graphql` unused dependencies `tracing-subscriber` and `trace`

* `examples/chat` deps `trace` and `tracing-subscriber` never be used. Add trace `debug` to `chat`

* remove `examples/print-request-response` unused dependency `axum-extra`

* remove `examples/prometheus-metrics` unused dependency `axum-extra`

* remove `examples/reverse-proxy` unused dependencies `tracing-subscriber` and `trace`

* `examples/chat` fmt fix

* fix `example-unix-domain-socket` compile error on not-unix platforms

Co-authored-by: zys864 <[email protected]>
Co-authored-by: zys864 <[email protected]>
2022-04-08 11:29:52 +02:00
Simon SellarandGitHub 59007d6111 Minor fixup of websocket example logging text. (#910) 2022-04-06 10:33:34 +00:00
David PedersenandGitHub 2270cf7b3e Add "stream to file" example (#903)
* Add "stream to file" example

* add title tag
2022-04-03 12:28:29 +02:00
David PedersenandGitHub 21552fe434 Remove bound from into_make_service_with_connect_info (#892)
Fixes #859
2022-03-31 16:49:49 +00:00
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 <[email protected]>
2022-03-31 10:03:06 +02:00
437fe5b931 Make status codes for JsonRejection more precise (#868)
* Fix status codes for `JsonRejection` rejections

Fixes #865

* Apply suggestions from code review

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

Co-authored-by: Jonas Platte <[email protected]>
2022-03-18 16:53:39 +01:00
David PedersenandGitHub 33ee55e52c Add example for consuming request body in middleware and extractor (#861) 2022-03-18 15:41:38 +00:00
Jonas PlatteandGitHub 79b94b9bd6 Replace set_var usage in examples (#829)
* examples: Fix inconsistent toml formatting

* examples: Replace set_var usage
2022-03-06 12:37:00 +01:00
Max BrucknerandGitHub 99fbd3d32c Add note about order of extractors in the reverse-proxy example (#821) 2022-03-03 22:33:33 +01:00
zys864andGitHub 768d8a8218 Fix minor issues in some examples (#806)
* remove unused `axum`'s dependency:`tokio-util`

* fix `examples/todos`'s `async fn todos_index` iter_overeager_cloned

* Add docs to `/examples/async-graphql`, just like other xamples.

* remove `examples/async-graphql` unused dependencies `tracing-subscriber` and `trace`

* `examples/chat` deps `trace` and `tracing-subscriber` never be used. Add trace `debug` to `chat`

* remove `examples/print-request-response` unused dependency `axum-extra`

* remove `examples/prometheus-metrics` unused dependency `axum-extra`

* remove `examples/reverse-proxy` unused dependencies `tracing-subscriber` and `trace`

* `examples/chat` fmt fix
2022-03-01 09:30:09 +00:00
David PedersenandGitHub a2b568c7c1 Implement tower::Layer for Extension (#801)
* Implement `tower::Layer` for `Extension`

* changelog
2022-03-01 00:39:22 +01:00
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 <[email protected]>

* changelog

Co-authored-by: Jonas Platte <[email protected]>
2022-02-28 23:04:33 +00:00
zys864andGitHub cb168b96fe fix examples/todos's async fn todos_index iter_overeager_cloned (#794)
* remove unused `axum`'s dependency:`tokio-util`

* fix `examples/todos`'s `async fn todos_index` iter_overeager_cloned
2022-02-25 15:29:23 +01:00
frobiacandGitHub 8c0926ee5b examples(jwt): Claims.exp represents a UTC timestamp (#760)
For the example to work, it should be an epoch value in the future.

See https://github.com/Keats/jsonwebtoken/blob/d8a33def00a61bab12aa5e94ff76d3043d4d474e/README.md?plain=1#L61
2022-02-15 21:43:31 +00:00
David PedersenandGitHub 409a6651f5 Update dependencies (#753) 2022-02-12 17:16:14 +00:00
EvgeniiandGitHub 0c16ce7649 fix: typo in a comment in a sqlx-postgres example (#744) 2022-02-04 08:14:34 +01:00
a04fc42d75 Rework middleware docs (#732)
* rework middleware docs

* Apply suggestions from code review

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

Co-authored-by: Jonas Platte <[email protected]>
2022-01-30 20:09:18 +01:00
YuKun LiuandGitHub c0473f2b6f Expand WebSocket example to match on Message (#723) 2022-01-25 15:31:33 +00:00
FlakMandGitHub 32c9ab3c56 Add sqlx example with migrations (#722)
* Add sqlx example with migrations

Simple use case for sqlx based on tokio postgres example.
Sqlite database is created on execution in ./target directory
and migrations are then run against it.

* sqlx example uses postgres instead of sqlite3

Also removed migrations and database creation code.
2022-01-25 16:20:00 +01:00
David PedersenandGitHub 9004a14302 Move middleware::from_fn into axum (#719)
* Move `middleware::from_fn` into axum

* changelog

* fix feature

* Rephrase changelog a bit
2022-01-25 10:19:06 +01:00
David Pedersen 184ea656c0 Change HeaderMap extractor to clone the headers (#698)
* Change `HeaderMap` extractor to clone the headers

* fix docs

* changelog

* inline variable

* also add changelog item to axum

* don't list types from axum in axum-core's changelog

* document that `HeaderMap::from_request` clones the headers

* fix typo

* a few more typos
2022-01-23 18:01:52 +01:00
Nick AshleyandDavid Pedersen 9b4232b786 Replace public use of mime crate with &str (#642)
Replaces `Field::content_type`'s return type with `&str`.
This is a breaking change.

Closes #637
2022-01-23 18:01:52 +01:00
Nick AshleyandGitHub 007a0e85f2 Use 308 instead of 301 for trailing slash redirects (#682)
* Use 308 status instead of 301 when redirecting

For redirects resulting from requests to paths with a trailing slash,
use 308 instead of 301 to prevent non-GET requests (POST, PUT, etc) from
being changed to GET.

For example, (assuming a route for /path is defined)...
  - Old behavior results in:
  POST /path/ -> GET /path

  - New behavior results in:
  POST /path/ -> POST /path

Fixes #681

* Add deprecation notice to found()

Deprecates found() due to its use of HTTP 302

* rustfmt

* Use dedicated redirect method

Use Redirect::permanent instead of re-implementing its functionality

* Remove deprecated method from example

Replace usages of Redirect:found with Redirect::to and Redirect::temporary as appropriate

* Fix panic in oauth example

Previously the example would panic if a request was made without the
`Cookie` header. Now the user is redirected to the login page as
expected.

* Update CHANGELOG

* Revert pub TypedheaderRejection fields

* Fix clippy lint

* cargo fmt

* Fix CHANGELOG link

* Adhere to implicit line length limit
2022-01-12 15:14:06 +01:00
David PedersenandGitHub 6d24a8695f Add SSE tests (#652)
* Add SSE tests

* Simplify keep alive test a bit

* More robust keep-alive tests

* rename a bit
2022-01-03 18:48:50 +01:00
Jonas PlatteandGitHub 616a43aaa3 Simplify graceful shutdown (#673) 2021-12-28 16:23:07 +01:00
David PedersenandGitHub 5698fb8be9 Add metrics example (#671) 2021-12-28 15:58:48 +01:00
Jonas PlatteandGitHub 0a399ed0fa A few small refactorings (#655)
* Simplify json content-type check

* Import HeaderMap from http instead of from headers

The headers crate is an optional dependency and its HeaderMap re-export
is `#[doc(hidden)]`.

* Use headers re-export in axum in examples
2021-12-27 14:02:38 +01:00
David PedersenandGitHub f4716084a7 Add middleware::from_fn for creating middleware from async fns (#656)
* Add `middleware::from_fn` for creating middleware from async fns

* More trait impls for `Next`

* Make `Next::run` consume `self`

* Use `.router_layer` in example, since middleware returns early

* Actually `Next` probably shouldn't impl `Clone` and `Service`

Has implications for backpressure and stuff

* Simplify `print-request-response` example

* Address review feedback

* add changelog link
2021-12-27 14:01:26 +01:00
3841ef44d5 Fix session cookie example (#638)
* refactor: refine session cookie example

* refactor: refine session_cookie extraction

* refactor: avoid to_owned()

* chore: refine debug log

Co-authored-by: 荒野無燈 <[email protected]>
2021-12-22 15:27:13 +01:00
David PedersenandGitHub ba42783df2 Example for defining routes and handlers close together (#621) 2021-12-12 23:54:18 +01:00
David PedersenandGitHub ecf3359980 Fix misc warnings from CI (#620) 2021-12-12 17:21:29 +01:00
Kai JewsonandGitHub 9ed18d92cf Use AtomicU32 in RouteId (#616) 2021-12-12 14:19:30 +00:00
Kai JewsonandGitHub dfb06e721c Introduce Response type alias as a shorthand for Response<BoxBody> (#590)
* Introduce `Response` type alias as a shorthand

* Don't re-export `Response` at the crate root
2021-12-05 19:16:46 +01:00
David PedersenandGitHub 3ec680cce7 Provide more data in Path deserialization error (#574)
* Provide more error in `Path` deserialization error

* Rename

* Add error kind for deserializing sequences

* Rename

* Fix wrong docs

* Rename `MissingRouteParams`

* Rename error to have more consistency

* Rename internal error

* Update changelog

* One last renaming, for now

* Add tests

* Tweak changelog a bit
2021-12-02 08:51:29 +01:00
David PedersenandGitHub 66c5142d0c Update tower-http (#581)
Updates to 0.2 which was just published.
2021-12-01 20:14:25 +00:00
David PedersenandGitHub 254d8fde17 Move FromRequest and IntoResponse into new axum-core crate (#564)
* Move `IntoResponse` to axum-core

* Move `FromRequest` to axum-core

* some clean up

* Remove hyper dependency from axum-core

* Fix docs reference

* Use default

* Update changelog

* Remove mention of default type
2021-11-30 13:46:13 +00:00