Unable to override cookie policy

オープン
#794 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
python

調査の方向性

httpx/_models.py の 334 行目と 1030 行目付近にあるリンク先のセクションから始め、次に httpx/_client.py の 400 行目付近を調べます。MozillaCookieJar の例を含め、CookieJar オブジェクトがどのようにコピーおよびマージされるかを追跡します。クライアントから提供された policy が保持され、リクエストレベルの policy がそれを上書きすれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Originally opened by @KKomarov on 2023-11-15 01:09:25 in encode/httpx

I would like to be able to override the cookie policy used by a Client when making a request. However, overriding the cookie policy on the cookie jar of the Client or of the Request object has had no effect. These lines of code explains why:

https://github.com/encode/httpx/blob/497b315fc7a0ca6a54c8ec6c929568abaf6efab1/httpx/_models.py#L334
https://github.com/encode/httpx/blob/497b315fc7a0ca6a54c8ec6c929568abaf6efab1/httpx/_models.py#L1030
When initialise request from existing cookies (which is Cookies object of Client), it discards policy object from source Cookies object.

https://github.com/encode/httpx/blob/497b315fc7a0ca6a54c8ec6c929568abaf6efab1/httpx/_client.py#L400
The cookie jars of both the client and the request are merged into a newly constructed CookieJar, discarding the policies of both.

What I expected to be able to do, and what isn't working currently, is something like the following:

        cookie = MozillaCookieJar(filename='cookies.txt', policy=MyCookiePolicy())
        cookie.load()
        session = httpx.Client(headers=headers, cookies=cookie)
        session.get(url)

In my opinion Policy from CookieJar in Client should not be discarded. When CookieJar object passed in request then policy from request should override policy from Client.

主要言語
Python
スター
1.6k
フォーク
103
平均マージ
1日 19時間
マージ済み PR(30日)
25

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pydantic/httpx2 のほかの issue

pydantic/httpx2 の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。