Mercurial > hg > FileServer
comparison tests/test_fileapp.txt @ 33:86b519dd8467
finish test and implementation
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 05 Mar 2012 14:08:31 -0800 |
parents | f00fcf6d9f1d |
children |
comparison
equal
deleted
inserted
replaced
32:0edb831061f5 | 33:86b519dd8467 |
---|---|
27 >>> content_length = os.path.getsize(filename) | 27 >>> content_length = os.path.getsize(filename) |
28 >>> content_length # don't ask me why the 'L' | 28 >>> content_length # don't ask me why the 'L' |
29 6L | 29 6L |
30 >>> req = Request.blank('/') | 30 >>> req = Request.blank('/') |
31 >>> res = req.get_response(app) | 31 >>> res = req.get_response(app) |
32 >>> print res | 32 >>> print res |
33 200 OK | 33 200 OK |
34 Content-Type: text/plain; charset=UTF-8 | 34 Content-Type: text/plain; charset=UTF-8 |
35 Content-Length: 6 | 35 Content-Length: 6 |
36 Last-Modified: ... GMT | 36 Last-Modified: ... GMT |
37 ETag: ...-... | 37 ETag: ...-... |
44 <Response ... 304 Not Modified> | 44 <Response ... 304 Not Modified> |
45 >>> req3 = Request.blank('/') | 45 >>> req3 = Request.blank('/') |
46 >>> req3.if_modified_since = res.last_modified | 46 >>> req3.if_modified_since = res.last_modified |
47 >>> req3.get_response(app) | 47 >>> req3.get_response(app) |
48 <Response ... 304 Not Modified> | 48 <Response ... 304 Not Modified> |
49 | |
50 We can even do Range requests:: | |
51 | |
52 >>> req = Request.blank('/') | |
53 >>> res = req.get_response(app) | |
54 >>> req2 = Request.blank('/') | |
55 >>> # Re-fetch the first 3 bytes: | |
56 >>> req2.range = (0, 3) | |
57 >>> res2 = req2.get_response(app) | |
58 >>> res2 | |
59 <Response ... 206 Partial Content> | |
60 >>> res2.body | |
61 'hel' | |
62 >>> # Now, conditional range support: | |
63 >>> req3 = Request.blank('/') | |
64 >>> req3.if_range = res.etag | |
65 >>> req3.range = (0, 3) | |
66 >>> req3.get_response(app) | |
67 <Response ... 206 Partial Content> | |
68 >>> req3.if_range = 'invalid-etag' | |
69 >>> req3.get_response(app) | |
70 <Response ... 200 OK> |