Adds the header `hdr: value` with the response. If `unique` is True and a header with that name already exists, it doesn't add a new one.
(hdr, value, unique=False)
| 383 | |
| 384 | |
| 385 | def header(hdr, value, unique=False): |
| 386 | """ |
| 387 | Adds the header `hdr: value` with the response. |
| 388 | |
| 389 | If `unique` is True and a header with that name already exists, |
| 390 | it doesn't add a new one. |
| 391 | """ |
| 392 | hdr, value = safestr(hdr), safestr(value) |
| 393 | # protection against HTTP response splitting attack |
| 394 | if "\n" in hdr or "\r" in hdr or "\n" in value or "\r" in value: |
| 395 | raise ValueError("invalid characters in header") |
| 396 | if unique is True: |
| 397 | for h, v in ctx.headers: |
| 398 | if h.lower() == hdr.lower(): |
| 399 | return |
| 400 | |
| 401 | ctx.headers.append((hdr, value)) |
| 402 | |
| 403 | |
| 404 | def rawinput(method=None): |