Here are the examples of the python api twisted.web.server.Request taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
22 Examples
3
Example 1
def setUp(self):
self.apserver = IAirPlayServerMock()
service = AirPlayService(self.apserver, "test")
service.deviceid = "01:00:17:44:60:d2"
self.apserver.features = 0x77
self.proto = http.HTTPChannel()
self.proto.requestFactory = server.Request
self.proto.site = server.Site(service.create_site())
self.proto.makeConnection(StringTransport())
3
Example 2
Project: mamba-framework Source File: test_mamba.py
def test_get_client_ip_with_x_forwarded(self):
d = DummyChannel()
request = server.Request(d, False)
request.gotLength(0)
request.requestHeaders.setRawHeaders(b"x-forwarded-for",
[b"80.80.80.80"])
request.requestReceived(b'GET', b'/foo%2Fbar', b'HTTP/1.0')
self.assertEqual(request.getClientIP(), '80.80.80.80')
3
Example 3
Project: mamba-framework Source File: test_mamba.py
def test_get_client_proxy_ip_with_x_forwarded(self):
d = DummyChannel()
request = server.Request(d, False)
request.gotLength(0)
request.requestHeaders.setRawHeaders(b"x-forwarded-for",
[b"80.80.80.80"])
request.requestReceived(b'GET', b'/foo%2Fbar', b'HTTP/1.0')
self.assertEqual(request.getClientProxyIP(), '192.168.1.1')
3
Example 4
Project: mamba-framework Source File: test_mamba.py
def test_get_client_ip_without_x_forwarded(self):
d = DummyChannel()
request = server.Request(d, False)
request.gotLength(0)
request.requestReceived(b'GET', b'/foo%2Fbar', b'HTTP/1.0')
self.assertEqual(request.getClientIP(), '192.168.1.1')
3
Example 5
Project: txrestapi Source File: tests.py
def test_returns_normal_resources(self):
r = APIResource()
a = Resource()
r.putChild('a', a)
req = Request(FakeChannel(), None)
a_ = r.getChild('a', req)
self.assertEqual(a, a_)
3
Example 6
Project: SubliminalCollaborator Source File: test_util.py
def test_headersAndCode(self):
"""
L{redirectTo} will set the C{Location} and C{Content-Type} headers on
its request, and set the response code to C{FOUND}, so the browser will
be redirected.
"""
request = Request(DummyChannel(), True)
request.method = 'GET'
targetURL = "http://target.example.com/4321"
redirectTo(targetURL, request)
self.assertEqual(request.code, FOUND)
self.assertEqual(
request.responseHeaders.getRawHeaders('location'), [targetURL])
self.assertEqual(
request.responseHeaders.getRawHeaders('content-type'),
['text/html; charset=utf-8'])
3
Example 7
Project: SubliminalCollaborator Source File: test_util.py
def test_redirectToUnicodeURL(self) :
"""
L{redirectTo} will raise TypeError if unicode object is passed in URL
"""
request = Request(DummyChannel(), True)
request.method = 'GET'
targetURL = u'http://target.example.com/4321'
self.assertRaises(TypeError, redirectTo, targetURL, request)
3
Example 8
def test_interface(self):
"""
L{server.Request} instances provide L{iweb.IRequest}.
"""
self.assertTrue(
verifyObject(iweb.IRequest, server.Request(DummyChannel(), True)))
3
Example 9
Project: SubliminalCollaborator Source File: test_web.py
def testChildLink(self):
request = server.Request(DummyChannel(), 1)
request.gotLength(0)
request.requestReceived('GET', '/foo/bar', 'HTTP/1.0')
self.assertEqual(request.childLink('baz'), 'bar/baz')
request = server.Request(DummyChannel(), 1)
request.gotLength(0)
request.requestReceived('GET', '/foo/bar/', 'HTTP/1.0')
self.assertEqual(request.childLink('baz'), 'baz')
3
Example 10
Project: SubliminalCollaborator Source File: test_web.py
def testPrePathURLSimple(self):
request = server.Request(DummyChannel(), 1)
request.gotLength(0)
request.requestReceived('GET', '/foo/bar', 'HTTP/1.0')
request.setHost('example.com', 80)
self.assertEqual(request.prePathURL(), 'http://example.com/foo/bar')
3
Example 11
Project: SubliminalCollaborator Source File: test_web.py
def testPrePathURLNonDefault(self):
d = DummyChannel()
d.transport.port = 81
request = server.Request(d, 1)
request.setHost('example.com', 81)
request.gotLength(0)
request.requestReceived('GET', '/foo/bar', 'HTTP/1.0')
self.assertEqual(request.prePathURL(), 'http://example.com:81/foo/bar')
3
Example 12
Project: SubliminalCollaborator Source File: test_web.py
def testPrePathURLSSLPort(self):
d = DummyChannel()
d.transport.port = 443
request = server.Request(d, 1)
request.setHost('example.com', 443)
request.gotLength(0)
request.requestReceived('GET', '/foo/bar', 'HTTP/1.0')
self.assertEqual(request.prePathURL(), 'http://example.com:443/foo/bar')
3
Example 13
Project: SubliminalCollaborator Source File: test_web.py
def testPrePathURLSSLPortAndSSL(self):
d = DummyChannel()
d.transport = DummyChannel.SSL()
d.transport.port = 443
request = server.Request(d, 1)
request.setHost('example.com', 443)
request.gotLength(0)
request.requestReceived('GET', '/foo/bar', 'HTTP/1.0')
self.assertEqual(request.prePathURL(), 'https://example.com/foo/bar')
3
Example 14
Project: SubliminalCollaborator Source File: test_web.py
def testPrePathURLHTTPPortAndSSL(self):
d = DummyChannel()
d.transport = DummyChannel.SSL()
d.transport.port = 80
request = server.Request(d, 1)
request.setHost('example.com', 80)
request.gotLength(0)
request.requestReceived('GET', '/foo/bar', 'HTTP/1.0')
self.assertEqual(request.prePathURL(), 'https://example.com:80/foo/bar')
3
Example 15
Project: SubliminalCollaborator Source File: test_web.py
def testPrePathURLSSLNonDefault(self):
d = DummyChannel()
d.transport = DummyChannel.SSL()
d.transport.port = 81
request = server.Request(d, 1)
request.setHost('example.com', 81)
request.gotLength(0)
request.requestReceived('GET', '/foo/bar', 'HTTP/1.0')
self.assertEqual(request.prePathURL(), 'https://example.com:81/foo/bar')
3
Example 16
Project: SubliminalCollaborator Source File: test_web.py
def testPrePathURLSetSSLHost(self):
d = DummyChannel()
d.transport.port = 81
request = server.Request(d, 1)
request.setHost('foo.com', 81, 1)
request.gotLength(0)
request.requestReceived('GET', '/foo/bar', 'HTTP/1.0')
self.assertEqual(request.prePathURL(), 'https://foo.com:81/foo/bar')
3
Example 17
Project: SubliminalCollaborator Source File: test_web.py
def test_prePathURLQuoting(self):
"""
L{Request.prePathURL} quotes special characters in the URL segments to
preserve the original meaning.
"""
d = DummyChannel()
request = server.Request(d, 1)
request.setHost('example.com', 80)
request.gotLength(0)
request.requestReceived('GET', '/foo%2Fbar', 'HTTP/1.0')
self.assertEqual(request.prePathURL(), 'http://example.com/foo%2Fbar')
3
Example 18
def testSimple(self):
r = resource.Resource()
r.isLeaf=0
rr = RootResource()
r.putChild('foo', rr)
rr.putChild('', rr)
rr.putChild('bar', resource.Resource())
chan = self.createServer(r)
for url in ['/foo/', '/foo/bar', '/foo/bar/baz', '/foo/bar/']:
request = server.Request(chan, 1)
request.setHost('example.com', 81)
request.gotLength(0)
request.requestReceived('GET', url, 'HTTP/1.0')
self.assertEqual(request.getRootURL(), "http://example.com/foo")
3
Example 19
def testRoot(self):
rr = RootResource()
rr.putChild('', rr)
rr.putChild('bar', resource.Resource())
chan = self.createServer(rr)
for url in ['/', '/bar', '/bar/baz', '/bar/']:
request = server.Request(chan, 1)
request.setHost('example.com', 81)
request.gotLength(0)
request.requestReceived('GET', url, 'HTTP/1.0')
self.assertEqual(request.getRootURL(), "http://example.com/")
3
Example 20
def _getReq(self, resource=None):
"""
Create a request object with a stub channel and install the
passed resource at /newrender. If no resource is passed,
create one.
"""
d = DummyChannel()
if resource is None:
resource = NewRenderResource()
d.site.resource.putChild('newrender', resource)
d.transport.port = 81
request = server.Request(d, 1)
request.setHost('example.com', 81)
request.gotLength(0)
return request
3
Example 21
def _getReq(self):
"""
Generate a dummy request for use by C{_computeAllowedMethod} tests.
"""
d = DummyChannel()
d.site.resource.putChild('gettableresource', GettableResource())
d.transport.port = 81
request = server.Request(d, 1)
request.setHost('example.com', 81)
request.gotLength(0)
return request
0
Example 22
def getRequest(method, url):
req = Request(FakeChannel(), None)
req.method = method
req.path = url
return req