Mercurial > hg > nginx
comparison src/http/ngx_http_core_module.c @ 3632:920919d9148c
ngx_http_send_response()
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 18 Jun 2010 15:08:44 +0000 |
parents | 31e9677b15a1 |
children | 40e356cf4176 |
comparison
equal
deleted
inserted
replaced
3631:eb5e237bfa58 | 3632:920919d9148c |
---|---|
1703 return; | 1703 return; |
1704 } | 1704 } |
1705 } | 1705 } |
1706 | 1706 |
1707 return; | 1707 return; |
1708 } | |
1709 | |
1710 | |
1711 ngx_int_t | |
1712 ngx_http_send_response(ngx_http_request_t *r, ngx_uint_t status, | |
1713 ngx_str_t *ct, ngx_http_complex_value_t *cv) | |
1714 { | |
1715 ngx_int_t rc; | |
1716 ngx_str_t val; | |
1717 ngx_buf_t *b; | |
1718 ngx_chain_t out; | |
1719 | |
1720 r->headers_out.status = status; | |
1721 | |
1722 if (status == NGX_HTTP_NO_CONTENT) { | |
1723 return ngx_http_send_header(r); | |
1724 } | |
1725 | |
1726 if (ngx_http_complex_value(r, cv, &val) != NGX_OK) { | |
1727 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1728 } | |
1729 | |
1730 if (status >= NGX_HTTP_MOVED_PERMANENTLY && status <= NGX_HTTP_SEE_OTHER) { | |
1731 | |
1732 r->headers_out.location = ngx_list_push(&r->headers_out.headers); | |
1733 if (r->headers_out.location == NULL) { | |
1734 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1735 } | |
1736 | |
1737 r->headers_out.location->hash = 1; | |
1738 ngx_str_set(&r->headers_out.location->key, "Location"); | |
1739 r->headers_out.location->value = val; | |
1740 | |
1741 return status; | |
1742 } | |
1743 | |
1744 r->headers_out.content_length_n = val.len; | |
1745 | |
1746 if (ct) { | |
1747 r->headers_out.content_type_len = ct->len; | |
1748 r->headers_out.content_type = *ct; | |
1749 | |
1750 } else { | |
1751 if (ngx_http_set_content_type(r) != NGX_OK) { | |
1752 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1753 } | |
1754 } | |
1755 | |
1756 if (r->method == NGX_HTTP_HEAD || (r != r->main && val.len == 0)) { | |
1757 return ngx_http_send_header(r); | |
1758 } | |
1759 | |
1760 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)); | |
1761 if (b == NULL) { | |
1762 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1763 } | |
1764 | |
1765 b->pos = val.data; | |
1766 b->last = val.data + val.len; | |
1767 b->memory = val.len ? 1 : 0; | |
1768 b->last_buf = (r == r->main) ? 1 : 0; | |
1769 b->last_in_chain = 1; | |
1770 | |
1771 out.buf = b; | |
1772 out.next = NULL; | |
1773 | |
1774 rc = ngx_http_send_header(r); | |
1775 | |
1776 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { | |
1777 return rc; | |
1778 } | |
1779 | |
1780 return ngx_http_output_filter(r, &out); | |
1708 } | 1781 } |
1709 | 1782 |
1710 | 1783 |
1711 ngx_int_t | 1784 ngx_int_t |
1712 ngx_http_send_header(ngx_http_request_t *r) | 1785 ngx_http_send_header(ngx_http_request_t *r) |