Commit Graph

77 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 3fde3be3d8
add trybuild tests to routing codegen (#1677) 2020-09-13 16:31:08 +01:00
Rob Ede 64a2c13cdf
the big three point oh (#1668) 2020-09-11 13:50:10 +01:00
Rob Ede 059d1671d7
prepare release beta 4 (#1659) 2020-09-09 22:14:11 +01:00
Yuki Okushi 5802eb797f
awc,web: Bump up to next beta releases (#1638) 2020-08-18 01:08:40 +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 92b5bcd13f
Check format and tweak CI config (#1619) 2020-07-22 00:28:33 +01:00
Rob Ede ad7c6d2633
prepare actix-web v3.0.0-beta.1 release (#1600) 2020-07-15 00:44:44 +01:00
Yuki Okushi 1382094c15
Avoid using deprecated `/` in license field 2020-07-14 11:19:56 +09:00
Rob Ede a70e599ff5
re-export rt in web and add main macro (#1575) 2020-06-22 20:09:48 +01:00
Yuki Okushi 8a106c07b4
Tweak codegen metadata 2020-05-25 16:45:34 +09:00
Yuki Okushi bb89d04080
codegen: Bump up to 0.2.2 2020-05-23 17:22:30 +09:00
Yuki Okushi fe89ba7027
Update `actix-web` dependency to 3.0.0-alpha.3 2020-05-21 17:32:36 +09:00
Yuki Okushi 24372467d9
codegen: Minimize `futures` dependencies 2020-05-19 08:29:11 +09:00
Rob Ede 996f1d7eae
bump msrv in ci and readme 2020-05-13 01:57:37 +01:00
Yuki Okushi b66c3083a5
Update the `actix-web` dependency to 3.0.0-alpha.2 2020-05-08 06:46:42 +09:00
Quentin de Quelen 9164ed1f0c
add resource middleware on actix-web-codegen (#1467)
Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
2020-05-07 18:31:12 +09:00
Ivan Tham 2067331884
Refactor actix-codegen duplicate code (#1423)
Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
2020-03-20 04:40:42 +09:00
Oleg Nosov c67e4c1fe8
Refactored macros (#1333)
Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
2020-03-15 07:23:28 +09:00
Yuki Okushi 1b28a5d48b
Update `actix-web` dependency to 3.0.0-alpha.1 2020-03-12 03:03:50 +09:00
Yuki Okushi a4f87a53da
Update CHANGES.md 2020-02-25 08:42:39 +09:00
Yuki Okushi 036ffd43f9 Prepare for new release 2020-02-23 06:40:02 +09:00
Matt Gathu 060c392c67
Add missing_docs attribute to generated structs 2020-02-22 10:32:12 +01:00
Andrey Torsunov 71d11644a7 Add ability to name a handler function as 'config' (#1290)
* eliminate handler naming restrictions #1277

* Update actix-web-codegen/CHANGES.md

Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
2020-01-26 07:22:40 +09:00
Nikolay Kim 8b8a9a995d bump ver 2019-12-20 17:36:48 +06:00
Nikolay Kim 232f71b3b5 update changes 2019-12-13 12:18:30 +06:00
Nikolay Kim 4937c9f9c2 refactor http-test server 2019-12-12 23:08:38 +06:00
Nikolay Kim 4a8a9ef405 update tests and clippy warnings 2019-12-08 12:31:16 +06:00
Nikolay Kim 14075ebf7f use released versions of actix-net 2019-12-02 23:33:39 +06:00
Nikolay Kim f4c01384ec update to latest actix-net 2019-12-02 17:33:11 +06:00
Folyd f43a706364 Set name for each generated resource 2019-11-26 19:25:28 +06:00
Nikolay Kim 4dc31aac93 use actix_rt::test for test setup 2019-11-26 11:25:50 +06:00
Nikolay Kim c1c44a7dd6 upgrade derive_more 2019-11-25 17:59:14 +06:00
Martell Malone 525c22de15 fix typos from updating to futures 0.3 2019-11-22 13:25:55 +06:00
Nikolay Kim 57981ca04a update tests to async handlers 2019-11-22 11:49:35 +06:00
Nikolay Kim 8683ba8bb0 rename .to_async() to .to() 2019-11-21 21:36:35 +06:00
Nikolay Kim 0de101bc4d update actix-web-codegen tests 2019-11-21 16:02:17 +06:00
Nikolay Kim 1ca9d87f0a prep actix-web-codegen release 2019-10-14 21:35:53 +06:00
DanSnow 967f965405 Update `syn` & `quote` to 1.0 (#1133)
* chore(actix-web-codegen): Upgrade syn and quote to 1.0

* feat(actix-web-codegen): Generate better error message

* doc(actix-web-codegen): Update CHANGES.md

* fix: Build with stable rust
2019-10-14 21:34:17 +06:00
Marat Safin cb19ebfe0c add rustls support for actix-http and awc (#998)
* add rustls support for actix-http and awc

* fix features conflict

* remove unnecessary duplication

* test server with rust-tls

* fix

* test rustls

* awc rustls test

* format

* tests

* fix dependencies

* fixes and add changes

* remove test-server and Cargo.toml dev-dependencies changes

* cargo fmt
2019-07-31 13:02:56 -07:00
Nikolay Kim 4092c7f326 clippy warnings 2019-07-17 15:08:30 +06:00
Nikolay Kim 686e5f1595 update deps 2019-06-16 22:10:22 +06:00
Nikolay Kim a548b69679 fmt 2019-06-05 08:43:13 +06:00
Nikolay Kim a771540b16 prepare actix-web-codegen release 2019-06-04 22:33:43 +06:00
Glade Miller cf217d35a8 Added HEAD, CONNECT, OPTIONS and TRACE to the codegen (#886)
* Added HEAD, CONNECT, OPTIONS and TRACE to the codegen

* Add new macros to use statement

* Add patch to supported codegen http methods

* Update CHANGES.md

Added head, options, trace, connect and patch codegen changes to CHANGES.md
2019-06-04 22:30:43 +06:00