MCPcopy Index your code
hub / github.com/webpy/webpy / request

Method request

web/application.py:151–260  ·  view source on GitHub ↗

Makes request to this application for the specified path and method. Response will be a storage object with data, status and headers. >>> urls = ("/hello", "hello") >>> app = application(urls, globals()) >>> class hello: ... def GET(self):

(
        self,
        localpart="/",
        method="GET",
        data=None,
        host="0.0.0.0:8080",
        headers=None,
        https=False,
        **kw,
    )

Source from the content-addressed store, hash-verified

149 self.processors.append(processor)
150
151 def request(
152 self,
153 localpart="/",
154 method="GET",
155 data=None,
156 host="0.0.0.0:8080",
157 headers=None,
158 https=False,
159 **kw,
160 ):
161 """Makes request to this application for the specified path and method.
162 Response will be a storage object with data, status and headers.
163
164 >>> urls = ("/hello", "hello")
165 >>> app = application(urls, globals())
166 >>> class hello:
167 ... def GET(self):
168 ... web.header('Content-Type', 'text/plain')
169 ... return "hello"
170 ...
171 >>> response = app.request("/hello")
172 >>> response.data
173 'hello'
174 >>> response.status
175 '200 OK'
176 >>> response.headers['Content-Type']
177 'text/plain'
178
179 To use https, use https=True.
180
181 >>> urls = ("/redirect", "redirect")
182 >>> app = application(urls, globals())
183 >>> class redirect:
184 ... def GET(self): raise web.seeother("/foo")
185 ...
186 >>> response = app.request("/redirect")
187 >>> response.headers['Location']
188 'http://0.0.0.0:8080/foo'
189 >>> response = app.request("/redirect", https=True)
190 >>> response.headers['Location']
191 'https://0.0.0.0:8080/foo'
192
193 The headers argument specifies HTTP headers as a mapping object
194 such as a dict.
195
196 >>> urls = ('/ua', 'uaprinter')
197 >>> class uaprinter:
198 ... def GET(self):
199 ... return 'your user-agent is ' + web.ctx.env['HTTP_USER_AGENT']
200 ...
201 >>> app = application(urls, globals())
202 >>> app.request('/ua', headers = {
203 ... 'User-Agent': 'a small jumping bean/1.0 (compatible)'
204 ... }).data
205 'your user-agent is a small jumping bean/1.0 (compatible)'
206
207 """
208 # PY3DOCTEST: b'hello'

Callers 15

test_reloaderMethod · 0.80
test_reloader_nestedMethod · 0.80
testUppercaseMethodsMethod · 0.80
testRedirectMethod · 0.80
test_routingMethod · 0.80
test_subdirsMethod · 0.80
testMethod · 0.80
test_redirectMethod · 0.80
test_processorsMethod · 0.80
fMethod · 0.80
testUnicodeInputMethod · 0.80
assert_notfoundMethod · 0.80

Calls 6

wsgifuncMethod · 0.95
urlencodeFunction · 0.85
itemsMethod · 0.80
popMethod · 0.80
encodeMethod · 0.80
joinMethod · 0.80

Tested by 14

test_reloaderMethod · 0.64
test_reloader_nestedMethod · 0.64
testUppercaseMethodsMethod · 0.64
testRedirectMethod · 0.64
test_routingMethod · 0.64
test_subdirsMethod · 0.64
testMethod · 0.64
test_redirectMethod · 0.64
test_processorsMethod · 0.64
fMethod · 0.64
testUnicodeInputMethod · 0.64
assert_notfoundMethod · 0.64