jjjake / internetarchive

A Python and Command-Line Interface to Archive.org
GNU Affero General Public License v3.0
1.58k stars 217 forks source link

Inconsistent request preparation #629

Open JustAnotherArchivist opened 7 months ago

JustAnotherArchivist commented 7 months ago

While working on my recent PR, I noticed that the request for uploading is prepared differently when debug mode is enabled. With debugging, it uses the session's prepare_request method:

https://github.com/jjjake/internetarchive/blob/6e2321652ab2bd13c517dabf5a6e01f420bca380/internetarchive/item.py#L1052-L1055

Without debugging, it uses the request's prepare method:

https://github.com/jjjake/internetarchive/blob/6e2321652ab2bd13c517dabf5a6e01f420bca380/internetarchive/item.py#L1070-L1071

I observed header differences between the two, but I can't immediately tell which is more correct, hence why I'm filing an issue rather than a PR. Note that the session.headers do get copied into the request directly inside _build_request. Changing the non-debug code to use self.session.prepare_request breaks several tests, too.

There's another case in Item.modify_metadata where the code directly contradicts the preceding comment:

https://github.com/jjjake/internetarchive/blob/6e2321652ab2bd13c517dabf5a6e01f420bca380/internetarchive/item.py#L840-L842