Make httpclient.put take a content-type instead of picking one

No reason to push the content-type decision into httpclient
This commit is contained in:
Jim Paris 2019-08-13 16:07:00 -04:00
parent 57751f5b32
commit 5d9fc5500c
3 changed files with 6 additions and 9 deletions

View File

@ -181,7 +181,7 @@ class Client(object):
}
if binary:
params["binary"] = 1
return self.http.put("stream/insert", data, params, binary)
return self.http.put("stream/insert", data, params)
def stream_intervals(self, path, start = None, end = None, diffpath = None):
"""

View File

@ -122,12 +122,10 @@ class HTTPClient(object):
else:
return self._req("POST", url, None, params)
def put(self, url, data, params = None, binary = False):
def put(self, url, data, params = None,
content_type = "application/octet-stream"):
"""Simple PUT (parameters in URL, data in body)"""
if binary:
h = { 'Content-type': 'application/octet-stream' }
else:
h = { 'Content-type': 'text/plain; charset=utf-8' }
h = { 'Content-type': content_type }
return self._req("PUT", url, query = params, body = data, headers = h)
# Generator versions that return data one line at a time.

View File

@ -259,8 +259,7 @@ class TestClient(object):
with assert_raises(ClientError) as e:
client.http.put("stream/insert", b"",
{ "path": "xxxx", "start": 0, "end": 1,
"binary": 1 },
binary = True)
"binary": 1 })
in_("No such stream", str(e.exception))
# Bad content type
@ -268,7 +267,7 @@ class TestClient(object):
client.http.put("stream/insert", b"",
{ "path": "xxxx", "start": 0, "end": 1,
"binary": 1 },
binary = False)
content_type="text/plain; charset=utf-8")
in_("Content type must be application/octet-stream", str(e.exception))
# Specify start/end (starts too late)