2015-01-22 11:10:03 +00:00
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
2015-01-28 09:22:15 +00:00
|
|
|
from sleekxmpp.xmlstream import ElementBase
|
2015-01-22 11:10:03 +00:00
|
|
|
|
|
|
|
|
2015-01-27 09:43:57 +00:00
|
|
|
class Request(ElementBase):
|
2015-01-22 11:10:03 +00:00
|
|
|
|
2015-01-28 09:22:15 +00:00
|
|
|
"""
|
|
|
|
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><html><header/><body><p>Beautiful home page.</p></body></html></text>
|
|
|
|
</data>
|
|
|
|
</req>
|
|
|
|
</iq>
|
|
|
|
"""
|
|
|
|
|
|
|
|
name = 'request'
|
2015-01-29 03:03:40 +00:00
|
|
|
namespace = 'urn:xmpp:http'
|
|
|
|
interfaces = set(['method', 'resource', 'version'])
|
2015-01-28 09:22:15 +00:00
|
|
|
plugin_attrib = 'req'
|
2015-01-22 11:10:03 +00:00
|
|
|
|
2015-01-29 03:03:40 +00:00
|
|
|
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)
|
|
|
|
|