

def advertise_alternative_service(self, field_value, origin=None, stream_id=None):
    '\n        Notify a client about an available Alternative Service.\n\n        An Alternative Service is defined in `RFC 7838\n        <https://tools.ietf.org/html/rfc7838>`_. An Alternative Service\n        notification informs a client that a given origin is also available\n        elsewhere.\n\n        Alternative Services can be advertised in two ways. Firstly, they can\n        be advertised explicitly: that is, a server can say "origin X is also\n        available at Y". To advertise like this, set the ``origin`` argument\n        and not the ``stream_id`` argument. Alternatively, they can be\n        advertised implicitly: that is, a server can say "the origin you\'re\n        contacting on stream X is also available at Y". To advertise like this,\n        set the ``stream_id`` argument and not the ``origin`` argument.\n\n        The explicit method of advertising can be done as long as the\n        connection is active. The implicit method can only be done after the\n        client has sent the request headers and before the server has sent the\n        response headers: outside of those points, Hyper-h2 will forbid sending\n        the Alternative Service advertisement by raising a ProtocolError.\n\n        The ``field_value`` parameter is specified in RFC 7838. Hyper-h2 does\n        not validate or introspect this argument: the user is required to\n        ensure that it\'s well-formed. ``field_value`` corresponds to RFC 7838\'s\n        "Alternative Service Field Value".\n\n        .. note:: It is strongly preferred to use the explicit method of\n                  advertising Alternative Services. The implicit method of\n                  advertising Alternative Services has a number of subtleties\n                  and can lead to inconsistencies between the server and\n                  client. Hyper-h2 allows both mechanisms, but caution is\n                  strongly advised.\n\n        .. versionadded:: 2.3.0\n\n        :param field_value: The RFC 7838 Alternative Service Field Value. This\n            argument is not introspected by Hyper-h2: the user is responsible\n            for ensuring that it is well-formed.\n        :type field_value: ``bytes``\n\n        :param origin: The origin/authority to which the Alternative Service\n            being advertised applies. Must not be provided at the same time as\n            ``stream_id``.\n        :type origin: ``bytes`` or ``None``\n\n        :param stream_id: The ID of the stream which was sent to the authority\n            for which this Alternative Service advertisement applies. Must not\n            be provided at the same time as ``origin``.\n        :type stream_id: ``int`` or ``None``\n\n        :returns: Nothing.\n        '
    if (not isinstance(field_value, bytes)):
        raise ValueError('Field must be bytestring.')
    if ((origin is not None) and (stream_id is not None)):
        raise ValueError('Must not provide both origin and stream_id')
    self.state_machine.process_input(ConnectionInputs.SEND_ALTERNATIVE_SERVICE)
    if (origin is not None):
        f = AltSvcFrame(stream_id=0)
        f.origin = origin
        f.field = field_value
        frames = [f]
    else:
        stream = self._get_stream_by_id(stream_id)
        frames = stream.advertise_alternative_service(field_value)
    self._prepare_for_sending(frames)

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