Skip to content

Commit

Permalink
Merge pull request #213 from KeepSafe/add_response_started_property
Browse files Browse the repository at this point in the history
Add prop
  • Loading branch information
asvetlov committed Dec 29, 2014
2 parents 2648c48 + 62bac2e commit cd0a957
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CHANGES
=======

0.13.1 (Unreleased)
--------------------

- Add `aiohttp.web.StreamResponse.started` property #213


0.13.0 (12-29-2014)
-------------------

Expand Down
4 changes: 4 additions & 0 deletions aiohttp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ def _copy_cookies(self):
value = cookie.output(header='')[1:]
self.headers.add('Set-Cookie', value)

@property
def started(self):
return self._resp_impl is not None

@property
def status(self):
return self._status
Expand Down
5 changes: 5 additions & 0 deletions docs/web.rst
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,11 @@ StreamResponse
parameter. Otherwise pass :class:`str` with
arbitrary *status* explanation..

.. attribute:: started

Read-only :class:`bool` property, ``True`` if :meth:`start` has
been called, ``False`` otherwise.

.. attribute:: status

Read-only property for *HTTP response status code*, :class:`int`.
Expand Down
9 changes: 9 additions & 0 deletions tests/test_web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,12 @@ def test_set_text_with_charset(self):
self.assertEqual("текст", resp.text)
self.assertEqual("текст".encode('koi8-r'), resp.body)
self.assertEqual("koi8-r", resp.charset)

def test_started_when_not_started(self):
resp = StreamResponse()
self.assertFalse(resp.started)

def test_started_when_started(self):
resp = StreamResponse()
resp.start(self.make_request('GET', '/'))
self.assertTrue(resp.started)

0 comments on commit cd0a957

Please sign in to comment.