summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/xep_0332/stanza/request.py
blob: 51e565e57fd406bf7a0934ed0693e46320d812bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
    SleekXMPP: The Sleek XMPP Library
    Implementation of HTTP over XMPP transport
    http://xmpp.org/extensions/xep-0332.html
    Copyright (C) 2015 Riptide IO, sangeeth@riptideio.com
    This file is part of SleekXMPP.

    See the file LICENSE for copying permission.
"""

from sleekxmpp.xmlstream import ElementBase


class Request(ElementBase):

    """
    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/user' 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>&lt;html&gt;&lt;header/&gt;&lt;body&gt;&lt;p&gt;Beautiful home page.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</text>
            </data>
        </req>
    </iq>
    """

    name = 'request'
    namespace = 'urn:xmpp:http'
    interfaces = set(['method', 'resource', 'version'])
    plugin_attrib = 'req'

    def get_method(self):
        print "Request:: get_method()"

    def set_method(self, method):
        print "Request:: set_method()"
        self._set_attr('method', method)

    def get_resource(self):
        print "Request:: get_resource()"

    def set_resource(self, resource):
        print "Request:: set_resource()"
        self._set_attr('resource', resource)

    def get_version(self):
        print "Request:: get_version()"

    def set_version(self, version='1.1'):
        print "Request:: set_version()"
        self._set_attr('version', version)