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

Function view_status_code

httpbin/core.py:350–375  ·  view source on GitHub ↗

Return status code or random status code if more than one are given

(codes)

Source from the content-addressed store, hash-verified

348
349@app.route('/status/<codes>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'TRACE'])
350def view_status_code(codes):
351 """Return status code or random status code if more than one are given"""
352
353 if ',' not in codes:
354 try:
355 code = int(codes)
356 except ValueError:
357 return Response('Invalid status code', status=400)
358 return status_code(code)
359
360 choices = []
361 for choice in codes.split(','):
362 if ':' not in choice:
363 code = choice
364 weight = 1
365 else:
366 code, weight = choice.split(':')
367
368 try:
369 choices.append((int(code), float(weight)))
370 except ValueError:
371 return Response('Invalid status code', status=400)
372
373 code = weighted_choice(choices)
374
375 return status_code(code)
376
377
378@app.route('/response-headers', methods=['GET', 'POST'])

Callers

nothing calls this directly

Calls 2

status_codeFunction · 0.85
weighted_choiceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…