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,
)
| 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' |