| 614 | } |
| 615 | |
| 616 | static int http_write_reply(URLContext* h, int status_code) |
| 617 | { |
| 618 | int ret, body = 0, reply_code, message_len; |
| 619 | const char *reply_text, *content_type; |
| 620 | HTTPContext *s = h->priv_data; |
| 621 | char message[BUFFER_SIZE]; |
| 622 | content_type = "text/plain"; |
| 623 | |
| 624 | if (status_code < 0) |
| 625 | body = 1; |
| 626 | switch (status_code) { |
| 627 | case AVERROR_HTTP_BAD_REQUEST: |
| 628 | case 400: |
| 629 | reply_code = 400; |
| 630 | reply_text = "Bad Request"; |
| 631 | break; |
| 632 | case AVERROR_HTTP_FORBIDDEN: |
| 633 | case 403: |
| 634 | reply_code = 403; |
| 635 | reply_text = "Forbidden"; |
| 636 | break; |
| 637 | case AVERROR_HTTP_NOT_FOUND: |
| 638 | case 404: |
| 639 | reply_code = 404; |
| 640 | reply_text = "Not Found"; |
| 641 | break; |
| 642 | case AVERROR_HTTP_TOO_MANY_REQUESTS: |
| 643 | case 429: |
| 644 | reply_code = 429; |
| 645 | reply_text = "Too Many Requests"; |
| 646 | break; |
| 647 | case 200: |
| 648 | reply_code = 200; |
| 649 | reply_text = "OK"; |
| 650 | content_type = s->content_type ? s->content_type : "application/octet-stream"; |
| 651 | break; |
| 652 | case AVERROR_HTTP_SERVER_ERROR: |
| 653 | case 500: |
| 654 | reply_code = 500; |
| 655 | reply_text = "Internal server error"; |
| 656 | break; |
| 657 | default: |
| 658 | return AVERROR(EINVAL); |
| 659 | } |
| 660 | if (body) { |
| 661 | s->chunked_post = 0; |
| 662 | message_len = snprintf(message, sizeof(message), |
| 663 | "HTTP/1.1 %03d %s\r\n" |
| 664 | "Content-Type: %s\r\n" |
| 665 | "Content-Length: %zu\r\n" |
| 666 | "%s" |
| 667 | "\r\n" |
| 668 | "%03d %s\r\n", |
| 669 | reply_code, |
| 670 | reply_text, |
| 671 | content_type, |
| 672 | strlen(reply_text) + 6, // 3 digit status code + space + \r\n |
| 673 | s->headers ? s->headers : "", |
no test coverage detected