havardgulldahl / jottalib

A library to access files stored at jottacloud.com.
GNU General Public License v3.0
83 stars 19 forks source link

monkeypatch urllib3 param function to bypass bug in jottacloud servers #27

Closed havardgulldahl closed 9 years ago

havardgulldahl commented 9 years ago

This is what we are doing to monkeypatch urllib3 param function to bypass bug in jottacloud servers

Requests/urllib3 correctly encodes the filename of a multipart/form-data transfer if it contains non-ascii characters, and then names the field filename* (with an asterisk). See thorough explanation

This is too much for the Jottacloud server.

Luckily, the server happily swallows the encoded filename, if we just make sure that the field name contains no asterisk.

So this is what we do since 6770ed88a3842251cda9e903dd9ac4e4028e9691 :

from requests.packages import urllib3
urllib3.fields.format_header_param_orig = urllib3.fields.format_header_param
def mp(name, value):
    return urllib3.fields.format_header_param_orig(name, value).replace('filename*=', 'filename=')
urllib3.fields.format_header_param = mp
havardgulldahl commented 9 years ago

Blast! I totally forgot that I'd already documented this in #9 . oh well.