Commit Graph

3340 Commits

Author SHA1 Message Date
Matt Gathu 8bb205846d Handle repeated HTTP Method edge case
Refactor code to detect when the same HTTP method is specified more than
once. eg. `#[route("/multi", method = "GET", method = "GET")]`
and return a compile time error.
2020-09-15 20:26:08 +02:00
Matt Gathu 90a6b47927 Simplify code generation + remove uppercase conversion
* assume HTTP methods always specified in uppercase e.g `GET`
* simplify code generation by quote!
2020-09-15 20:26:08 +02:00
Matt Gathu c5c8d21c84 Update Change log 2020-09-15 20:26:08 +02:00
Matt Gathu 55ddb4877c Update route attribute macro syntax 2020-09-15 20:26:08 +02:00
Matt Gathu 9539456656 Add route macro tests 2020-09-15 20:26:08 +02:00
Matt Gathu 31348a2339 Provide attribute macro for multiple HTTP methods
What
--
Define a new `route` attribute macro that supports defining multiple
HTTP methods to routed to (handled by) a single handler.

The attribute macro syntax looks like this
```rust
use actix_web::route;

async fn multi_methods() -> &'static str {
    "Hello world!\r\n"
}
```

How
--
This implementation extends the [`GuardType`][1] enum in actix-web-codegen to have a
new `GuardType::Multi` variant that denotes when multiple method guards
are used.

A new `methods` attribute in the `route` attribute macro provides a
comma-separated list of HTTP methods to provide guard for.

The code parses the methods list, matches them to the respective
`GuardType` and uses the `AnyGuard` struct to combine them together.

A constructor method for [`AnyGuard`][2] is added to support this.

The generated code looks like this:
```rust
pub struct multi_methods;
impl actix_web::dev::HttpServiceFactory for multi_methods {
    fn register(self, __config: &mut actix_web::dev::AppService) {
    ¦   async fn multi_methods() -> &'static str {
    ¦   ¦   "Hello world!\r\n"
    ¦   }
    ¦   let __resource = actix_web::Resource::new("/multi")
    ¦   ¦   .name("multi_methods")
    ¦   ¦   .guard(actix_web:💂:AnyGuard::new(<[_]>::into_vec(box [
    ¦   ¦   ¦   Box::new(actix_web:💂:Get()),
    ¦   ¦   ¦   Box::new(actix_web:💂:Post()),
    ¦   ¦   ])))
    ¦   ¦   .to(multi_methods);
    ¦   actix_web::dev::HttpServiceFactory::register(__resource, __config)
    }
}
```

**NOTE: This is my first attempt that implementing this feature.
Feedback and mentorship is highly welcome to improve it :-)**

Why
--
This fixes https://github.com/actix/actix-web/issues/1360

[1]: https://github.com/actix/actix-web/blob/master/actix-web-codegen/src/route.rs#L21
[2]: https://github.com/actix/actix-web/blob/master/src/guard.rs#L104s
2020-09-15 20:26:08 +02:00
Rob Ede d707704556
prepare web release 3.0.2 (#1681) 2020-09-15 13:14:14 +01:00
Aleksandrov Vladimir a429ee6646
Add possibility to set address for test_server (#1645) 2020-09-15 12:09:16 +01:00
Rob Ede 7f8073233a
fix trimming to inaccessible root path (#1678) 2020-09-15 11:32:31 +01:00
Rob Ede 4b4c9d1b93
update migration guide
closes #1680
2020-09-14 22:26:03 +01:00
Rob Ede 3fde3be3d8
add trybuild tests to routing codegen (#1677) 2020-09-13 16:31:08 +01:00
Rob Ede f861508789
prepare web release 3.0.1 (#1676) 2020-09-13 03:24:44 +01:00
Damian Lesiuk a4546f02d2
make TrailingSlash enum accessible (#1673)
Co-authored-by: Damian Lesiuk <lesiuk@sabre.com>
2020-09-13 00:55:39 +01:00
Rob Ede 64a2c13cdf
the big three point oh (#1668) 2020-09-11 13:50:10 +01:00
Rob Ede bf53fe5a22
bump actix dependency to v0.10 (#1666) 2020-09-11 12:09:52 +01:00
Rob Ede cf5138e740
fix clippy async_yields_async lints (#1667) 2020-09-11 11:29:17 +01:00
Igor Aleksanov 121075c1ef
awc: Rename Client::build to Client::builder (#1665) 2020-09-11 09:24:39 +01:00
Robert Gabriel Jakabosky 22089aff87
Improve json, form and query extractor config docs (#1661) 2020-09-10 15:40:20 +01:00
Rob Ede 7787638f26
fix CI clippy warnings (#1664) 2020-09-10 14:46:35 +01:00
Rob Ede 2f6e9738c4
prepare multipart and actors releases (#1663) 2020-09-10 12:54:27 +01:00
Mufeed VH e39d166a17
Fix examples hyperlink in README (#1660) 2020-09-10 00:12:50 +01:00
Rob Ede 059d1671d7
prepare release beta 4 (#1659) 2020-09-09 22:14:11 +01:00
Igor Aleksanov 3a27580ebe
awc: improve module documentation (#1656)
Co-authored-by: Rob Ede <robjtede@icloud.com>
2020-09-09 14:24:12 +01:00
Rob Ede 9d0534999d
bump connect and tls versions (#1655) 2020-09-09 09:20:54 +01:00
Igor Aleksanov c54d73e0bb
Improve awc websocket docs (#1654)
Co-authored-by: Rob Ede <robjtede@icloud.com>
2020-09-07 12:04:54 +01:00
Rob Ede 9a9d4b182e
document all remaining unsafe usages (#1642)
adds some debug assertions where appropriate
2020-09-03 10:00:24 +01:00
Rob Ede 4e321595bc
extract more config types from Data<T> as well (#1641) 2020-09-02 22:12:07 +01:00
Matt Kantor 01cbef700f
Fix a small typo in a doc comment. (#1649) 2020-08-28 22:16:41 +01:00
Rob Ede 8497b5f490
integrate with updated actix-{codec, utils} (#1634) 2020-08-24 10:13:35 +01:00
LJ 75d86a6beb
Configurable trailing slash behaviour for NormalizePath (#1639)
Co-authored-by: ljoonal <ljoona@ljoonal.xyz>
2020-08-19 12:21:52 +01:00
Yuki Okushi 3892a95c11
Fix actix-web version to publish 2020-08-18 01:16:18 +09:00
Yuki Okushi 5802eb797f
awc,web: Bump up to next beta releases (#1638) 2020-08-18 01:08:40 +09:00
Yuki Okushi ff2ca0f420
Update rustls to 0.18 (#1637) 2020-08-18 00:28:39 +09:00
Yuki Okushi 59ad1738e9
web: Bump up to 3.0.0-beta.2 (#1636) 2020-08-17 11:32:38 +01:00
Yuki Okushi aa2bd6fbfb
http: Bump up to 2.0.0-beta.3 (#1630) 2020-08-14 19:42:14 +09:00
William Myers 5aad8e24c7
Re-export all error types from awc (#1621) 2020-08-14 01:24:35 +01:00
Yuki Okushi 6e97bc09f8
Use action to upload docs 2020-08-13 16:04:50 +09:00
fakeshadow 160995b8d4
fix awc pool leak (#1626) 2020-08-09 21:49:43 +01:00
Rob Ede 187646b2f9
match HttpRequest app_data behavior in ServiceRequest (#1618) 2020-08-09 15:51:38 +01:00
Rob Ede 46627be36f
add dep graph dot graphs (#1601) 2020-08-09 13:54:35 +01:00
Rob Ede a78380739e
require rustls feature for client example (#1625) 2020-08-09 13:32:37 +01:00
Rob Ede cf1c8abe62
prepare release http & awc (#1617) 2020-07-22 01:13:10 +01:00
Yuki Okushi 92b5bcd13f
Check format and tweak CI config (#1619) 2020-07-22 00:28:33 +01:00
masnagam 701bdacfa2
Fix illegal chunked encoding (#1615)
Co-authored-by: Rob Ede <robjtede@icloud.com>
2020-07-21 17:24:56 +01:00
Rob Ede 6dc47c4093
fix soundness concern in h1 decoder (#1614)
Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
2020-07-21 16:25:33 +01:00
Rob Ede 0ec335a39c
bump MSRV to 1.42 (#1616) 2020-07-21 16:40:30 +09:00
Jonas Platte f8d5ad6b53
Make web::Path a tuple struct with a public inner value (#1594)
Co-authored-by: Rob Ede <robjtede@icloud.com>
2020-07-21 00:54:26 +01:00
Rob Ede 43c362779d
also try extracting payload config as Data<T> (#1610) 2020-07-20 17:40:58 +01:00
Rob Ede 971ba3eee1
fix continous growth of app data in pooled requests (#1609)
fixes #1606
fixes #1607
2020-07-18 16:17:00 +01:00
Rob Ede 2fd96c03e5
prepare beta.1 release for multipart/files/actors (#1605) 2020-07-16 11:38:57 +01:00