Exemplo n.º 1
0
ret_t
cherokee_handler_admin_add_headers (cherokee_handler_admin_t *hdl, cherokee_buffer_t *buffer)
{
    cherokee_connection_t *conn = HANDLER_CONN(hdl);

    if (cherokee_connection_should_include_length(conn)) {
        HANDLER(hdl)->support = hsupport_length;
        cherokee_buffer_add_va (buffer, "Content-Length: %lu" CRLF, hdl->reply.len);
    }

    return ret_ok;
}
Exemplo n.º 2
0
ret_t
cherokee_handler_ssi_add_headers (cherokee_handler_ssi_t *hdl,
                                  cherokee_buffer_t      *buffer)
{
	ret_t                  ret;
	char                  *ext;
	cherokee_buffer_t     *mime = NULL;
	cherokee_server_t     *srv  = HANDLER_SRV(hdl);
	cherokee_connection_t *conn = HANDLER_CONN(hdl);

	/* MIME type
	 */
	if (srv->mime != NULL) {
		ext = strrchr (conn->request.buf, '.');
		if (ext == NULL)
			return ret_ok;

		ret = cherokee_mime_get_by_suffix (srv->mime, ext+1, &hdl->mime);
		if (ret == ret_ok) {
			cherokee_mime_entry_get_type (hdl->mime, &mime);

			cherokee_buffer_add_str    (buffer, "Content-Type: ");
			cherokee_buffer_add_buffer (buffer, mime);
			cherokee_buffer_add_str    (buffer, CRLF);
		}
	}

	/* Length
	 */
	if (cherokee_connection_should_include_length(conn)) {
		HANDLER(hdl)->support = hsupport_length;

		cherokee_buffer_add_str     (buffer, "Content-Length: ");
		cherokee_buffer_add_ullong10(buffer, (cullong_t) hdl->render.len);
		cherokee_buffer_add_str     (buffer, CRLF);
	}

	return ret_ok;
}
Exemplo n.º 3
0
ret_t
cherokee_handler_error_add_headers (cherokee_handler_error_t *hdl, cherokee_buffer_t *buffer)
{
	cherokee_connection_t *conn = HANDLER_CONN(hdl);

	/* It has special headers on protocol upgrading
	 */
	switch (conn->upgrade) {
	case http_upgrade_nothing:
		break;
	case http_upgrade_tls10:
		cherokee_buffer_add_str (buffer, "Upgrade: TLS/1.0, HTTP/1.1"CRLF);
		break;
	case http_upgrade_http11:
		cherokee_buffer_add_str (buffer, "Upgrade: HTTP/1.1"CRLF);
		break;
	default:
		SHOULDNT_HAPPEN;
	}

	/* 1xx, 204 and 304 (Not Modified) responses have to be managed
	 * by "content" handlers, anyway this test ensures that
	 * it'll never send wrong and unrelated headers in case that
	 * a 1xx, 204 or 304 response is managed by this handler.
	 * 304 responses should only include the
	 * Last-Modified, ETag, Expires and Cache-Control headers.
	 */
	if (!http_code_with_body (conn->error_code)) {
		return ret_ok;
	}

	if (cherokee_connection_should_include_length(conn)) {

		HANDLER(hdl)->support |= hsupport_length;

		if (conn->error_code == http_range_not_satisfiable) {
			/* The handler that attended the request has put the content
			* length in conn->range_end in order to allow it to send the
			* right length to the client.
			*
			* "Content-Range: bytes *" "/" FMT_OFFSET CRLF
			*/
			cherokee_buffer_add_str     (buffer, "Content-Range: bytes */");
			cherokee_buffer_add_ullong10(buffer, (cullong_t)conn->range_end);
			cherokee_buffer_add_str     (buffer, CRLF);
		}

		cherokee_buffer_add_str     (buffer, "Content-Length: ");
		cherokee_buffer_add_ulong10 (buffer, (culong_t) hdl->content.len);
		cherokee_buffer_add_str     (buffer, CRLF);
	}

	/* Usual headers
	 */
	cherokee_buffer_add_str (buffer, "Content-Type: text/html"CRLF);

	if (http_type_400(conn->error_code) ||
	    http_type_500(conn->error_code))
	{
		cherokee_buffer_add_str (buffer, "Cache-Control: no-cache"CRLF);
		cherokee_buffer_add_str (buffer, "Pragma: no-cache"CRLF);
	}

	return ret_ok;
}