aio-libs / aio-libs/aiohttp

Warn the user when Authorization header is dropped from the request

Đang mở
#9,694 10 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement reproducer: missing
Ngôn ngữ chính
Python
Star
16.5k
Fork
2.4k
Merge trung bình
17 giờ 22 phút
Pull request đã merge (30 ngày)
212

Mô tả

### Is your feature request related to a problem?

As per the documentation -
```
Authorization header will be removed if you get redirected to a different host or protocol.
```
However this happens silently and can lead to confusion for the programmer.

### Describe the solution you'd like

The library should throw a warning letting the user know that the header has been dropped.
I went through the code and it seems the change below should be sufficient -
```diff
diff --git a/aiohttp/client.py b/aiohttp/client.py
index dc1ab674..8154b11f 100644
--- a/aiohttp/client.py
+++ b/aiohttp/client.py
@@ -756,7 +756,13 @@ class ClientSession:
and url.origin() != redirect_origin
):
auth = None
- headers.pop(hdrs.AUTHORIZATION, None)
+ auth_header = headers.pop(hdrs.AUTHORIZATION, None)
+ if auth_header:
+ warnings.warn(
+ message = "Authorization header has been removed from the request",
+ category = RuntimeWarning,
+ source = self,
+ )

url = parsed_redirect_url
```

### Describe alternatives you've considered

-

### Related component

Client

### Additional context

_No response_

### Code of Conduct

- [X] I agree to follow the aio-libs Code of Conduct

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.