Skip to content
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

[RFC] Alternative approach to "related events". #240

Merged
merged 3 commits into from
Jun 28, 2016
Merged
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
1 change: 1 addition & 0 deletions h2/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,7 @@ def _receive_headers_frame(self, frame):

if 'PRIORITY' in frame.flags:
p_frames, p_events = self._receive_priority_frame(frame)
stream_events[0].priority_updated = p_events[0]
stream_events.extend(p_events)
assert not p_frames

Expand Down
67 changes: 67 additions & 0 deletions h2/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class RequestReceived(object):
.. versionchanged:: 2.3.0
Changed the type of ``headers`` to :class:`HeaderTuple
<hpack:hpack.HeaderTuple>`. This has no effect on current users.

.. versionchanged:: 2.4.0
Added ``stream_ended`` and ``priority_updated`` properties.
"""
def __init__(self):
#: The Stream ID for the stream this request was made on.
Expand All @@ -31,6 +34,20 @@ def __init__(self):
#: The request headers.
self.headers = None

#: If this request also ended the stream, the associated
#: :class:`StreamEnded <h2.events.StreamEnded>` event will be available
#: here.
#:
#: .. versionadded:: 2.4.0
self.stream_ended = None

#: If this request also had associated priority information, the
#: associated :class:`PriorityUpdated <h2.events.PriorityUpdated>`
#: event will be available here.
#:
#: .. versionadded:: 2.4.0
self.priority_updated = None

def __repr__(self):
return "<RequestReceived stream_id:%s, headers:%s>" % (
self.stream_id, self.headers
Expand All @@ -46,6 +63,9 @@ class ResponseReceived(object):
.. versionchanged:: 2.3.0
Changed the type of ``headers`` to :class:`HeaderTuple
<hpack:hpack.HeaderTuple>`. This has no effect on current users.

.. versionchanged:: 2.4.0
Added ``stream_ended`` and ``priority_updated`` properties.
"""
def __init__(self):
#: The Stream ID for the stream this response was made on.
Expand All @@ -54,6 +74,20 @@ def __init__(self):
#: The response headers.
self.headers = None

#: If this response also ended the stream, the associated
#: :class:`StreamEnded <h2.events.StreamEnded>` event will be available
#: here.
#:
#: .. versionadded:: 2.4.0
self.stream_ended = None

#: If this response also had associated priority information, the
#: associated :class:`PriorityUpdated <h2.events.PriorityUpdated>`
#: event will be available here.
#:
#: .. versionadded:: 2.4.0
self.priority_updated = None

def __repr__(self):
return "<ResponseReceived stream_id:%s, headers:%s>" % (
self.stream_id, self.headers
Expand All @@ -72,6 +106,9 @@ class TrailersReceived(object):
.. versionchanged:: 2.3.0
Changed the type of ``headers`` to :class:`HeaderTuple
<hpack:hpack.HeaderTuple>`. This has no effect on current users.

.. versionchanged:: 2.4.0
Added ``stream_ended`` and ``priority_updated`` properties.
"""
def __init__(self):
#: The Stream ID for the stream on which these trailers were received.
Expand All @@ -80,6 +117,19 @@ def __init__(self):
#: The trailers themselves.
self.headers = None

#: Trailers always end streams. This property has the associated
#: :class:`StreamEnded <h2.events.StreamEnded>` in it.
#:
#: .. versionadded:: 2.4.0
self.stream_ended = None

#: If the trailers also set associated priority information, the
#: associated :class:`PriorityUpdated <h2.events.PriorityUpdated>`
#: event will be available here.
#:
#: .. versionadded:: 2.4.0
self.priority_updated = None

def __repr__(self):
return "<TrailersReceived stream_id:%s, headers:%s>" % (
self.stream_id, self.headers
Expand All @@ -104,6 +154,9 @@ class InformationalResponseReceived(object):
.. versionchanged:: 2.3.0
Changed the type of ``headers`` to :class:`HeaderTuple
<hpack:hpack.HeaderTuple>`. This has no effect on current users.

.. versionchanged:: 2.4.0
Added ``priority_updated`` property.
"""
def __init__(self):
#: The Stream ID for the stream this informational response was made
Expand All @@ -113,6 +166,13 @@ def __init__(self):
#: The headers for this informational response.
self.headers = None

#: If this response also had associated priority information, the
#: associated :class:`PriorityUpdated <h2.events.PriorityUpdated>`
#: event will be available here.
#:
#: .. versionadded:: 2.4.0
self.priority_updated = None

def __repr__(self):
return "<InformationalResponseReceived stream_id:%s, headers:%s>" % (
self.stream_id, self.headers
Expand All @@ -138,6 +198,13 @@ def __init__(self):
#: than ``len(data)``.
self.flow_controlled_length = None

#: If this data chunk also completed the stream, the associated
#: :class:`StreamEnded <h2.events.StreamEnded>` event will be available
#: here.
#:
#: .. versionadded:: 2.4.0
self.stream_ended = None

def __repr__(self):
return (
"<DataReceived stream_id:%s, "
Expand Down
8 changes: 6 additions & 2 deletions h2/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,9 +901,11 @@ def receive_headers(self, headers, end_stream, header_encoding):
events = self.state_machine.process_input(input_)

if end_stream:
events += self.state_machine.process_input(
es_events = self.state_machine.process_input(
StreamInputs.RECV_END_STREAM
)
events[0].stream_ended = es_events[0]
events += es_events

self._initialize_content_length(headers)

Expand All @@ -926,9 +928,11 @@ def receive_data(self, data, end_stream, flow_control_len):
self._track_content_length(len(data), end_stream)

if end_stream:
events += self.state_machine.process_input(
es_events = self.state_machine.process_input(
StreamInputs.RECV_END_STREAM
)
events[0].stream_ended = es_events[0]
events.extend(es_events)

events[0].data = data
events[0].flow_controlled_length = flow_control_len
Expand Down
Loading