actix / actix/actix-web

get route macro does not result in HEAD request support

Đang mở
#2,702 6 bình luận 11 reaction 0 người được giao Xem trên GitHub
A-web C-improvement help-wanted
Ngôn ngữ chính
Rust
Star
24.8k
Fork
1.9k
Merge trung bình
23 giờ 10 phút
Pull request đã merge (30 ngày)
26

Mô tả

## Example test case

```
#[get("/foo")]
async fn foo() -> impl Responder {
"foo\r\n"
}
```

## Current Behavior
```
$ curl -v http://localhost:8080/foo
...
* Trying 127.0.0.1...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x55e8ff381fb0)
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /foo HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.64.0
> Accept: */*
>
< HTTP/1.1 200 OK
< content-length: 5
< content-type: text/plain; charset=utf-8
< date: Sat, 19 Mar 2022 18:30:00 GMT
<
foo
* Connection #0 to host localhost left intact
$ curl -v -I http://localhost:8080/foo
...
* Expire in 0 ms for 1 (transfer 0x55f159685fb0)
* Trying 127.0.0.1...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x55f159685fb0)
* Connected to localhost (127.0.0.1) port 8080 (#0)
> HEAD /foo HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.64.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
HTTP/1.1 404 Not Found
< content-length: 0
content-length: 0
< date: Sat, 19 Mar 2022 18:30:58 GMT
date: Sat, 19 Mar 2022 18:30:58 GMT

<
* Connection #0 to host localhost left intact
$
```

## Expected Behavior

The `HEAD` request is implemented according to the RFC specification.

I can obtain the expected behaviour by writing:
```
#[route("/foo", method="GET", method="HEAD")]
```
but this is not ergonomic.

## Possible Solutions

1. Make the `get` macro work like `#[route("/foo", method="GET", method="HEAD")]` (and adjust documentation accordingly). This would mean that if an application author writes the obvious code, it is also correct.

2. Provide a new macro that behaves like `#[route("/foo", method="GET", method="HEAD")]`, and try to discourage application authors from using `#[get]`.

## References

[MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD), [RFC7231 4.3.2](https://httpwg.org/specs/rfc7231.html#HEAD).

## Your Environment

- Rust Version (I.e, output of `rustc -V`): `rustc 1.61.0-nightly (1bfe40d11 2022-03-18)`
- Actix Web Version: 4.0.1

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.