MCPcopy
hub / github.com/postmanlabs/httpbin / status_code

Function status_code

httpbin/helpers.py:208–256  ·  view source on GitHub ↗

Returns response object of given status code.

(code)

Source from the content-addressed store, hash-verified

206
207
208def status_code(code):
209 """Returns response object of given status code."""
210
211 redirect = dict(headers=dict(location=REDIRECT_LOCATION))
212
213 code_map = {
214 301: redirect,
215 302: redirect,
216 303: redirect,
217 304: dict(data=''),
218 305: redirect,
219 307: redirect,
220 401: dict(headers={'WWW-Authenticate': 'Basic realm="Fake Realm"'}),
221 402: dict(
222 data='Fuck you, pay me!',
223 headers={
224 'x-more-info': 'http://vimeo.com/22053820'
225 }
226 ),
227 406: dict(data=json.dumps({
228 'message': 'Client did not request a supported media type.',
229 'accept': ACCEPTED_MEDIA_TYPES
230 }),
231 headers={
232 'Content-Type': 'application/json'
233 }),
234 407: dict(headers={'Proxy-Authenticate': 'Basic realm="Fake Realm"'}),
235 418: dict( # I'm a teapot!
236 data=ASCII_ART,
237 headers={
238 'x-more-info': 'http://tools.ietf.org/html/rfc2324'
239 }
240 ),
241
242 }
243
244 r = make_response()
245 r.status_code = code
246
247 if code in code_map:
248
249 m = code_map[code]
250
251 if 'data' in m:
252 r.data = m['data']
253 if 'headers' in m:
254 r.headers = m['headers']
255
256 return r
257
258
259def check_basic_auth(user, passwd):

Callers 6

view_status_codeFunction · 0.85
basic_authFunction · 0.85
hidden_basic_authFunction · 0.85
cacheFunction · 0.85
etagFunction · 0.85
imageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…