Skip to content

Commit

Permalink
resolve now defaulting to HEAD method when applicable
Browse files Browse the repository at this point in the history
Fix #854
  • Loading branch information
Yomguithereal committed Sep 6, 2024
1 parent c59c21c commit 6989491
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/web.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ redirections = resolve("https://www.lemonde.fr/", stateful=True)
*Arguments*

- **url** *str*: url to request.
- **method** *Optional[str]*: HTTP method to use when resolving. Default to `HEAD` if no body sniffing is required, else `GET`.
- **headers** *Optional[dict[str, str]]*: HTTP headers, as a dict, to use for the request.
- **cookie** *Optional[str | dict[str, str]]*: cookie string to pass as the `Cookie` header value. Can also be a cookie morsel dict mapping names to their values.
- **spoof_ua** *bool* `False`: whether to use a plausible `User-Agent` header when performing the query.
Expand Down
8 changes: 7 additions & 1 deletion minet/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ def request(
def resolve(
url: str,
pool_manager: urllib3.PoolManager = DEFAULT_POOL_MANAGER,
method: str = "GET",
method: Optional[str] = None,
headers: Optional[Dict[str, str]] = None,
cookie: Optional[Union[str, Dict[str, str]]] = None,
spoof_ua: bool = False,
Expand All @@ -1111,6 +1111,12 @@ def resolve(
raise_on_statuses: Optional[Container[int]] = None,
stateful: bool = False,
) -> RedirectionStack:
if method is None:
method = "HEAD"

if follow_meta_refresh or follow_js_relocation or canonicalize:
method = "GET"

final_headers = build_request_headers(
headers=headers, cookie=cookie, spoof_ua=spoof_ua
)
Expand Down

0 comments on commit 6989491

Please sign in to comment.