Skip to content

Bump minimum and target version and drop Connection: close header when possible #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ matrix:

env:
global:
- IPFS_VERSION=0.4.19
- IPFS_SHA512_LINUX=66d930bef0196c70f25cb207c00da6e36f6c2c17ff0e785f45d360e710502c233aeeeaaa5ee0bfc984919d42225c74c6474e5e5ce5c8cd6993580903fa8ec0c4
- IPFS_SHA512_DARWIN=4453499e83f9a980c6dd423d55ae6893d48a16c3bebaba0bd8ac6961e4b75d7e20ac7aa125a3d88baac3233b3536a246144b39ff3a91ec8ad6a61482292369f5
- IPFS_VERSION=0.4.21
- IPFS_SHA512_LINUX=f344969cad4c2a4f81692c5e7e11dafc420694653fa37d1e389b5c458ee88ea34ea22efceb747351bb579247f1c494e47f667e7a178e8197ba4cad43a6e52f87
- IPFS_SHA512_DARWIN=cbb85560182a6af4187029b24414a217d706c4dd636aa0634061479d103ca9ec9f94b44787d131e9697d1347c6026dd42e70a9185e0917920bbe81f010154051


# Ensure go-IPFS is available for testing
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ Check out [the HTTP Client reference](https://ipfs.io/ipns/12D3KooWEqnTdgqHnkkwa
See the [relevant section of the README](#important-changes-from-ipfsapi-04x) for details.

**Note:** This library constantly has to change to stay compatible with the IPFS HTTP API.
Currently, this library is tested against [go-ipfs v0.4.19](https://github.com/ipfs/go-ipfs/releases/tag/v0.4.19).
You may experience compatibility issues when attempting to use it with other versions of go-ipfs.
Currently, this library is tested against [go-ipfs v0.4.21](https://github.com/ipfs/go-ipfs/releases/tag/v0.4.21).
We strive to support the last 5 releases of go-IPFS at any given time; go-IPFS v0.4.17 therefor
being to oldest supported version at this time.

The following versions have been expliciently backlisted for know compatiblity problems:

Expand Down
12 changes: 10 additions & 2 deletions ipfshttpclient/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
DEFAULT_ADDR = multiaddr.Multiaddr(os.environ.get("PY_IPFS_HTTP_CLIENT_DEFAULT_ADDR", '/dns/localhost/tcp/5001/http'))
DEFAULT_BASE = str(os.environ.get("PY_IPFS_HTTP_CLIENT_DEFAULT_BASE", 'api/v0'))

VERSION_MINIMUM = "0.4.3"
VERSION_MINIMUM = "0.4.17"
VERSION_BLACKLIST = ["0.4.20"]
VERSION_MAXIMUM = "0.5.0"

Expand Down Expand Up @@ -98,7 +98,15 @@ def connect(addr=DEFAULT_ADDR, base=DEFAULT_BASE,
client = Client(addr, base, chunk_size, session, **defaults)

# Query version number from daemon and validate it
assert_version(client.version()['Version'])
version_str = client.version()["Version"]
assert_version(version_str)

# Apply workarounds based on daemon version
version = tuple(map(int, version_str.split('-', 1)[0].split('.')))
if version < (0, 4, 19): # pragma: no cover (workaround)
#WORKAROUND: Go-IPFS randomly fucks up streaming requests if they are not
# `Connection: close` (https://github.com/ipfs/go-ipfs/issues/5168)
client._workarounds.add("close_conn_on_upload")

return client

Expand Down
4 changes: 3 additions & 1 deletion ipfshttpclient/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,6 @@ def __init__(self, addr=DEFAULT_ADDR, base=DEFAULT_BASE,

self._client = self._clientfactory(addr, base, **defaults)
if session:
self._client.open_session()
self._client.open_session()

self._workarounds = self._client.workarounds
11 changes: 10 additions & 1 deletion ipfshttpclient/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ class HTTPClient(object):
The address where the IPFS daemon may be reached
base : str
The path prefix for API calls
workarounds : Set[str]
List of daemon workarounds to apply
timeout : Union[numbers.Real, Tuple[numbers.Real, numbers.Real], NoneType]
The default number of seconds to wait when establishing a connection to
the daemon and waiting for returned data before throwing
Expand All @@ -164,7 +166,7 @@ class HTTPClient(object):

__metaclass__ = abc.ABCMeta

def __init__(self, addr, base, **defaults):
def __init__(self, addr, base, workarounds=None, **defaults):
addr = multiaddr.Multiaddr(addr)
addr_iter = iter(addr.items())

Expand Down Expand Up @@ -222,6 +224,8 @@ def __init__(self, addr, base, **defaults):

self.defaults = defaults
self._session = None

self.workarounds = workarounds if workarounds else set()

def open_session(self):
"""Open a persistent backend session that allows reusing HTTP
Expand Down Expand Up @@ -282,6 +286,11 @@ def _do_raise_for_status(self, response):

def _request(self, method, url, params, parser, stream=False, files=None,
headers={}, data=None, timeout=120):
if "close_conn_on_upload" in self.workarounds \
and method.upper() not in ("GET", "HEAD"): # pragma: no cover (workaround)
headers = headers.copy()
headers["Connection"] = "close"

# Do HTTP request (synchronously)
res = self._do_request(method, url, params=params, stream=stream,
files=files, headers=headers, data=data,
Expand Down
4 changes: 0 additions & 4 deletions ipfshttpclient/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ def __init__(self, name, chunk_size=default_chunk_size):
self._headers = content_disposition_headers(name, disptype='form-data')
self._headers.update(multipart_content_type_headers(self._boundary, subtype='form-data'))

#WORKAROUND: Go-IPFS randomly fucks up streaming requests if they are not
# `Connection: close` (https://github.com/ipfs/go-ipfs/issues/5168)
self._headers["Connection"] = "close"

super(StreamBase, self).__init__()

def headers(self):
Expand Down
3 changes: 1 addition & 2 deletions test/unit/test_multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ def test__gen_headers(self):
name = "test_name"
generator = StreamBaseSub(name)

expected = b'Connection: close\r\n' \
+ b'Content-Disposition: form-data; filename="test_name"\r\n' \
expected = b'Content-Disposition: form-data; filename="test_name"\r\n' \
+ b'Content-Type: multipart/form-data; ' \
+ b'boundary="' + generator._boundary.encode() + b'"\r\n\r\n'

Expand Down