| 3387 | */ |
| 3388 | |
| 3389 | int /* O - 0 on success, -1 on error */ |
| 3390 | httpWriteResponse(http_t *http, /* I - HTTP connection */ |
| 3391 | http_status_t status) /* I - Status code */ |
| 3392 | { |
| 3393 | http_encoding_t old_encoding; /* Old data_encoding value */ |
| 3394 | off_t old_remaining; /* Old data_remaining value */ |
| 3395 | cups_lang_t *lang; /* Response language */ |
| 3396 | |
| 3397 | |
| 3398 | /* |
| 3399 | * Range check input... |
| 3400 | */ |
| 3401 | |
| 3402 | DEBUG_printf(("httpWriteResponse(http=%p, status=%d)", (void *)http, status)); |
| 3403 | |
| 3404 | if (!http || status < HTTP_STATUS_CONTINUE) |
| 3405 | { |
| 3406 | DEBUG_puts("1httpWriteResponse: Bad input."); |
| 3407 | return (-1); |
| 3408 | } |
| 3409 | |
| 3410 | /* |
| 3411 | * Set the various standard fields if they aren't already... |
| 3412 | */ |
| 3413 | |
| 3414 | if (!http->fields[HTTP_FIELD_DATE]) |
| 3415 | httpSetField(http, HTTP_FIELD_DATE, httpGetDateString(time(NULL))); |
| 3416 | |
| 3417 | if (status >= HTTP_STATUS_BAD_REQUEST && http->keep_alive) |
| 3418 | { |
| 3419 | http->keep_alive = HTTP_KEEPALIVE_OFF; |
| 3420 | httpSetField(http, HTTP_FIELD_KEEP_ALIVE, ""); |
| 3421 | } |
| 3422 | |
| 3423 | if (http->version == HTTP_VERSION_1_1) |
| 3424 | { |
| 3425 | if (!http->fields[HTTP_FIELD_CONNECTION]) |
| 3426 | { |
| 3427 | if (http->keep_alive) |
| 3428 | httpSetField(http, HTTP_FIELD_CONNECTION, "Keep-Alive"); |
| 3429 | else |
| 3430 | httpSetField(http, HTTP_FIELD_CONNECTION, "close"); |
| 3431 | } |
| 3432 | |
| 3433 | if (http->keep_alive && !http->fields[HTTP_FIELD_KEEP_ALIVE]) |
| 3434 | httpSetField(http, HTTP_FIELD_KEEP_ALIVE, "timeout=10"); |
| 3435 | } |
| 3436 | |
| 3437 | #ifdef HAVE_TLS |
| 3438 | if (status == HTTP_STATUS_UPGRADE_REQUIRED || |
| 3439 | status == HTTP_STATUS_SWITCHING_PROTOCOLS) |
| 3440 | { |
| 3441 | if (!http->fields[HTTP_FIELD_CONNECTION]) |
| 3442 | httpSetField(http, HTTP_FIELD_CONNECTION, "Upgrade"); |
| 3443 | |
| 3444 | if (!http->fields[HTTP_FIELD_UPGRADE]) |
| 3445 | httpSetField(http, HTTP_FIELD_UPGRADE, "TLS/1.2,TLS/1.1,TLS/1.0"); |
| 3446 |
no test coverage detected