Example #1
0
 def connect(self):  # pragma: no cover
     raise exceptions.Http2ProtocolException(
         "HTTP2 layer should already have a connection.")
Example #2
0
 def disconnect(self):  # pragma: no cover
     raise exceptions.Http2ProtocolException(
         "Cannot dis- or reconnect in HTTP2 connections.")
Example #3
0
 def raise_zombie(self, pre_command=None):
     if self.zombie is not None:
         if pre_command is not None:
             pre_command()
         raise exceptions.Http2ProtocolException("Zombie Stream")
Example #4
0
 def safe_send_headers(self, is_zombie, stream_id, headers):
     with self.lock:
         if is_zombie():  # pragma: no cover
             raise exceptions.Http2ProtocolException("Zombie Stream")
         self.send_headers(stream_id, headers.fields)
         self.conn.send(self.data_to_send())
Example #5
0
 def send_response_body(self, _response, chunks):
     self.client_conn.h2.safe_send_body(self.is_zombie,
                                        self.client_stream_id, chunks)
     if self.zombie:  # pragma: no cover
         raise exceptions.Http2ProtocolException("Zombie Stream")
Example #6
0
 def set_server(self):  # pragma: no cover
     raise exceptions.Http2ProtocolException(
         "Cannot change server for HTTP2 connections.")
Example #7
0
    def send_request(self, message):
        if self.pushed:
            # nothing to do here
            return

        while True:
            if self.zombie:  # pragma: no cover
                raise exceptions.Http2ProtocolException("Zombie Stream")

            self.server_conn.h2.lock.acquire()

            max_streams = self.server_conn.h2.remote_settings.max_concurrent_streams
            if self.server_conn.h2.open_outbound_streams + 1 >= max_streams:
                # wait until we get a free slot for a new outgoing stream
                self.server_conn.h2.lock.release()
                time.sleep(0.1)
                continue

            # keep the lock
            break

        # We must not assign a stream id if we are already a zombie.
        if self.zombie:  # pragma: no cover
            raise exceptions.Http2ProtocolException("Zombie Stream")

        self.server_stream_id = self.server_conn.h2.get_next_available_stream_id()
        self.server_to_client_stream_ids[self.server_stream_id] = self.client_stream_id

        headers = message.headers.copy()
        headers.insert(0, ":path", message.path)
        headers.insert(0, ":method", message.method)
        headers.insert(0, ":scheme", message.scheme)

        priority_exclusive = None
        priority_depends_on = None
        priority_weight = None
        if self.handled_priority_event:
            # only send priority information if they actually came with the original HeadersFrame
            # and not if they got updated before/after with a PriorityFrame
            priority_exclusive = self.priority_exclusive
            priority_depends_on = self._map_depends_on_stream_id(self.server_stream_id, self.priority_depends_on)
            priority_weight = self.priority_weight

        try:
            self.server_conn.h2.safe_send_headers(
                self.is_zombie,
                self.server_stream_id,
                headers,
                end_stream=self.no_body,
                priority_exclusive=priority_exclusive,
                priority_depends_on=priority_depends_on,
                priority_weight=priority_weight,
            )
        except Exception as e:  # pragma: no cover
            raise e
        finally:
            self.server_conn.h2.lock.release()

        if not self.no_body:
            self.server_conn.h2.safe_send_body(
                self.is_zombie,
                self.server_stream_id,
                [message.body]
            )

        if self.zombie:  # pragma: no cover
            raise exceptions.Http2ProtocolException("Zombie Stream")