Skip to content
Back to top
View this page

# XEP-0332: HTTP over XMPP transport

class slixmpp.plugins.xep_0332.XEP_0332(xmpp, config=None)

  XEP-0332: HTTP over XMPP transport

  default_config: ClassVar[dict[str, Any]] = {'supported_headers': {'Accept', 'Accept-Charset', 'Accept-Encoding', 'Content-Encoding', 'Content-ID', 'Content-Language', 'Content-Length', 'Content-Location', 'Content-Transfer-Encoding', 'Content-Type', 'Date', 'DateTime', 'Description', 'Distribute', 'ETag', 'Error-Info', 'Expect', 'Expires', 'Host', 'Identifier', 'Location', 'Proxy-Authenticate', 'Proxy-Authorization', 'Server', 'Timestamp', 'Transfer-Encoding', 'User-Agent', 'WWW-Authenticate'}}

    TODO: Do we really need to mention the supported_headers?!

  dependencies: ClassVar[set[str]] = {'xep_0030', 'xep_0131'}

    xep_0047 not included. xep_0001, 0137 and 0166 are missing

  description: str = 'XEP-0332: HTTP over XMPP transport'

    A longer name for the plugin, describing its purpose. For example, a plugin for XEP-0030 would use ‘Service Discovery’ as its description value.

  name: str = 'xep_0332'

    A short name for the plugin based on the implemented specification. For example, a plugin for XEP-0030 would use ‘xep_0030’.

## Stanza elements

class slixmpp.plugins.xep_0332.stanza.data.HTTPData(xml=None, parent=None)

  The data element.

  get_data(encoding='text')
  interfaces: ClassVar[set[str]] = {'data'}

    The set of keys that the stanza provides for accessing and manipulating the underlying XML object. This set may be augmented with the `plugin_attrib` value of any registered stanza plugins.

  is_extension: ClassVar[bool] = True

    If you need to add a new interface to an existing stanza, you can create a plugin and set `is_extension = True`. Be sure to set the `plugin_attrib` value to the desired interface name, and that it is the only interface listed in `interfaces`. Requests for the new interface from the parent stanza will be passed to the plugin directly.

    Added in version 1.0-Beta5.

  name: ClassVar[str] = 'data'

    The XML tag name of the element, not including any namespace prefixes. For example, an `ElementBase` object for `<message />` would use `name = 'message'`.

  namespace: str = 'urn:xmpp:http'

    The XML namespace for the element. Given `<foo xmlns="bar" />`, then `namespace = "bar"` should be used. The default namespace is `jabber:client` since this is being used in an XMPP library.

  plugin_attrib: ClassVar[str] = 'data'

    For `ElementBase` subclasses which are intended to be used as plugins, the `plugin_attrib` value defines the plugin name. Plugins may be accessed by using the `plugin_attrib` value as the interface. An example using `plugin_attrib = 'foo'`:

        register_stanza_plugin(Message, FooPlugin)
        msg = Message()
        msg['foo']['an_interface_from_the_foo_plugin']

  set_data(data, encoding='text')

class slixmpp.plugins.xep_0332.stanza.request.HTTPRequest(xml=None, parent=None)

  All HTTP communication is done using the Request/Response paradigm. Each HTTP Request is made sending an iq stanza containing a req element to the server. Each iq stanza sent is of type set.

  Examples:

      <iq type='set' from='a@b.com/browser' to='x@y.com' id='1'>
          <req xmlns='urn:xmpp:http'
               method='GET'
               resource='/api/users'
               version='1.1'>
              <headers xmlns='http://jabber.org/protocol/shim'>
                  <header name='Host'>b.com</header>
              </headers>
          </req>
      </iq>

      <iq type='set' from='a@b.com/browser' to='x@y.com' id='2'>
          <req xmlns='urn:xmpp:http'
               method='PUT'
               resource='/api/users'
               version='1.1'>
              <headers xmlns='http://jabber.org/protocol/shim'>
                  <header name='Host'>b.com</header>
                  <header name='Content-Type'>text/html</header>
                  <header name='Content-Length'>...</header>
              </headers>
              <data>
                  <text>...</text>
              </data>
          </req>
      </iq>

  get_method()
  get_resource()
  get_version()
  interfaces: ClassVar[set[str]] = {'method', 'resource', 'version'}

    The set of keys that the stanza provides for accessing and manipulating the underlying XML object. This set may be augmented with the `plugin_attrib` value of any registered stanza plugins.

  name: ClassVar[str] = 'request'

    The XML tag name of the element, not including any namespace prefixes. For example, an `ElementBase` object for `<message />` would use `name = 'message'`.

  namespace: str = 'urn:xmpp:http'

    The XML namespace for the element. Given `<foo xmlns="bar" />`, then `namespace = "bar"` should be used. The default namespace is `jabber:client` since this is being used in an XMPP library.

  plugin_attrib: ClassVar[str] = 'http-req'

    For `ElementBase` subclasses which are intended to be used as plugins, the `plugin_attrib` value defines the plugin name. Plugins may be accessed by using the `plugin_attrib` value as the interface. An example using `plugin_attrib = 'foo'`:

        register_stanza_plugin(Message, FooPlugin)
        msg = Message()
        msg['foo']['an_interface_from_the_foo_plugin']

  set_method(method)
  set_resource(resource)
  set_version(version='1.1')

class slixmpp.plugins.xep_0332.stanza.response.HTTPResponse(xml=None, parent=None)

  When the HTTP Server responds, it does so by sending an iq stanza response (type=`result`) back to the client containing the resp element. Since response are asynchronous, and since multiple requests may be active at the same time, responses may be returned in a different order than the in which the original requests were made.

  Examples:

      <iq type='result'
          from='httpserver@clayster.com'
          to='httpclient@clayster.com/browser' id='2'>
          <resp xmlns='urn:xmpp:http'
                version='1.1'
                statusCode='200'
                statusMessage='OK'>
              <headers xmlns='http://jabber.org/protocol/shim'>
                  <header name='Date'>Fri, 03 May 2013 16:39:54GMT-4</header>
                  <header name='Server'>Clayster</header>
                  <header name='Content-Type'>text/turtle</header>
                  <header name='Content-Length'>...</header>
                  <header name='Connection'>Close</header>
              </headers>
              <data>
                  <text>
                      ...
                  </text>
              </data>
          </resp>
      </iq>

  get_code()
  get_message()
  interfaces: ClassVar[set[str]] = {'code', 'message', 'version'}

    The set of keys that the stanza provides for accessing and manipulating the underlying XML object. This set may be augmented with the `plugin_attrib` value of any registered stanza plugins.

  name: ClassVar[str] = 'response'

    The XML tag name of the element, not including any namespace prefixes. For example, an `ElementBase` object for `<message />` would use `name = 'message'`.

  namespace: str = 'urn:xmpp:http'

    The XML namespace for the element. Given `<foo xmlns="bar" />`, then `namespace = "bar"` should be used. The default namespace is `jabber:client` since this is being used in an XMPP library.

  plugin_attrib: ClassVar[str] = 'http-resp'

    For `ElementBase` subclasses which are intended to be used as plugins, the `plugin_attrib` value defines the plugin name. Plugins may be accessed by using the `plugin_attrib` value as the interface. An example using `plugin_attrib = 'foo'`:

        register_stanza_plugin(Message, FooPlugin)
        msg = Message()
        msg['foo']['an_interface_from_the_foo_plugin']

  set_code(code)
  set_message(message)
  set_version(version='1.1')