Browse Source

Clean up stream/extract content-type and add a test for it

tags/nilmdb-1.5.0
Jim Paris 11 years ago
parent
commit
8292dcf70b
2 changed files with 15 additions and 3 deletions
  1. +4
    -3
      nilmdb/server/server.py
  2. +11
    -0
      tests/test_client.py

+ 4
- 3
nilmdb/server/server.py View File

@@ -398,7 +398,6 @@ class Stream(NilmApp):
# /stream/extract?path=/newton/prep&start=1234567890.0&end=1234567899.0 # /stream/extract?path=/newton/prep&start=1234567890.0&end=1234567899.0
@cherrypy.expose @cherrypy.expose
@chunked_response @chunked_response
@response_type("text/plain")
def extract(self, path, start = None, end = None, def extract(self, path, start = None, end = None,
count = False, markup = False, binary = False): count = False, markup = False, binary = False):
""" """
@@ -424,11 +423,13 @@ class Stream(NilmApp):
raise cherrypy.HTTPError("404", "No such stream: " + path) raise cherrypy.HTTPError("404", "No such stream: " + path)


if binary: if binary:
cherrypy.response.headers['Content-Type'] = (
"application/octet-stream")
content_type = "application/octet-stream"
if markup or count: if markup or count:
raise cherrypy.HTTPError("400", "can't mix binary and " raise cherrypy.HTTPError("400", "can't mix binary and "
"markup or count modes") "markup or count modes")
else:
content_type = "text/plain"
cherrypy.response.headers['Content-Type'] = content_type


@workaround_cp_bug_1200 @workaround_cp_bug_1200
def content(start, end): def content(start, end):


+ 11
- 0
tests/test_client.py View File

@@ -383,6 +383,17 @@ class TestClient(object):
raise AssertionError("/stream/extract is not text/plain:\n" + raise AssertionError("/stream/extract is not text/plain:\n" +
headers()) headers())


x = http.get("stream/extract",
{ "path": "/newton/prep",
"start": "123",
"end": "124",
"binary": "1" })
if "transfer-encoding: chunked" not in headers():
warnings.warn("Non-chunked HTTP response for /stream/extract")
if "content-type: application/octet-stream" not in headers():
raise AssertionError("/stream/extract is not binary:\n" +
headers())

client.close() client.close()


def test_client_08_unicode(self): def test_client_08_unicode(self):


Loading…
Cancel
Save