

def send_headers(self, stream_id, headers, end_stream=False):
    '\n        Send headers on a given stream.\n\n        This function can be used to send request or response headers: the kind\n        that are sent depends on whether this connection has been opened as a\n        client or server connection, and whether the stream was opened by the\n        remote peer or not.\n\n        If this is a client connection, calling ``send_headers`` will send the\n        headers as a request. It will also implicitly open the stream being\n        used. If this is a client connection and ``send_headers`` has *already*\n        been called, this will send trailers instead.\n\n        If this is a server connection, calling ``send_headers`` will send the\n        headers as a response. It is a protocol error for a server to open a\n        stream by sending headers. If this is a server connection and\n        ``send_headers`` has *already* been called, this will send trailers\n        instead.\n\n        When acting as a server, you may call ``send_headers`` any number of\n        times allowed by the following rules, in this order:\n\n        - zero or more times with ``(\':status\', \'1XX\')`` (where ``1XX`` is a\n          placeholder for any 100-level status code).\n        - once with any other status header.\n        - zero or one time for trailers.\n\n        That is, you are allowed to send as many informational responses as you\n        like, followed by one complete response and zero or one HTTP trailer\n        blocks.\n\n        Clients may send one or two header blocks: one request block, and\n        optionally one trailer block.\n\n        If it is important to send HPACK "never indexed" header fields (as\n        defined in `RFC 7451 Section 7.1.3\n        <https://tools.ietf.org/html/rfc7541#section-7.1.3>`_), the user may\n        instead provide headers using the HPACK library\'s :class:`HeaderTuple\n        <hpack:hpack.HeaderTuple>` and :class:`NeverIndexedHeaderTuple\n        <hpack:hpack.NeverIndexedHeaderTuple>` objects.\n\n        .. warning:: In HTTP/2, it is mandatory that all the HTTP/2 special\n            headers (that is, ones whose header keys begin with ``:``) appear\n            at the start of the header block, before any normal headers.\n            If you pass a dictionary to the ``headers`` parameter, it is\n            unlikely that they will iterate in that order, and your connection\n            may fail. For this reason, passing a ``dict`` to ``headers`` is\n            *deprecated*, and will be removed in 3.0.\n\n        .. versionchanged:: 2.3.0\n           Added support for using :class:`HeaderTuple\n           <hpack:hpack.HeaderTuple>` objects to store headers.\n\n        :param stream_id: The stream ID to send the headers on. If this stream\n            does not currently exist, it will be created.\n        :type stream_id: ``int``\n        :param headers: The request/response headers to send.\n        :type headers: An iterable of two tuples of bytestrings or\n            :class:`HeaderTuple <hpack:hpack.HeaderTuple>` objects.\n        :returns: Nothing\n        '
    if (stream_id not in self.streams):
        max_open_streams = self.remote_settings.max_concurrent_streams
        if ((self.open_outbound_streams + 1) > max_open_streams):
            raise TooManyStreamsError(('Max outbound streams is %d, %d open' % (max_open_streams, self.open_outbound_streams)))
    self.state_machine.process_input(ConnectionInputs.SEND_HEADERS)
    stream = self._get_or_create_stream(stream_id, AllowedStreamIDs(self.client_side))
    frames = stream.send_headers(headers, self.encoder, end_stream)
    self._prepare_for_sending(frames)

dataset/ETHPy150Open python-hyper/hyper-h2/h2/connection.py H2Connection.send_headers/original