Permalink
Browse files

The POST management code has been rewritten from scratch. The new

subsystem can relay POST information to handlers on-the-fly. This
means that the reverse proxy server and *cgi handlers can read the
information as the client sends it (~ better uploads).

git-svn-id: svn://cherokee-project.com/cherokee/trunk@4139 5dc97367-97f1-0310-9951-d761b3857238
  • Loading branch information...
alobbs committed Jan 20, 2010
1 parent fe0ecb6 commit 475ecb24084c79a706f15ce8198e3e95829f4d35
View
@@ -1458,18 +1458,16 @@ $(static_gen_evhost_src) \
$(static_collector_rrd_src) \
\
$(static_handler_file_src) \
-$(static_handler_admin_src) \
$(static_handler_dirlist_src) \
-$(static_handler_scgi_src) \
+$(static_handler_cgi_src) \
$(static_handler_fcgi_src) \
+$(static_handler_scgi_src) \
+$(static_handler_proxy_src) \
$(static_handler_uwsgi_src) \
-$(static_handler_fastcgi_src) \
$(static_handler_redir_src) \
$(static_handler_error_redir_src) \
$(static_handler_error_nn_src) \
-$(static_handler_cgi_src) \
$(static_handler_common_src) \
-$(static_handler_proxy_src) \
$(static_handler_ssi_src) \
$(static_handler_secdownload_src) \
$(static_handler_empty_gif_src) \
@@ -1478,6 +1476,7 @@ $(static_handler_custom_error_src) \
$(static_handler_server_info_src) \
$(static_handler_render_rrd_src) \
$(static_handler_dbslayer_src) \
+$(static_handler_admin_src) \
\
$(static_logger_ncsa_src) \
$(static_logger_custom_src) \
@@ -1559,6 +1558,8 @@ spawner.c \
collector.h \
collector.c
+#$(static_handler_fastcgi_src)
+
libcherokee_config_la_SOURCES = \
admin_client.h \
@@ -1641,17 +1642,15 @@ $(dynamic_vrule_target_ip_lib) \
$(dynamic_collector_rrd_lib) \
$(dynamic_gen_evhost_lib) \
$(dynamic_handler_file_lib) \
-$(dynamic_handler_cgi_lib) \
$(dynamic_handler_server_info_lib) \
$(dynamic_handler_render_rrd_lib) \
-$(dynamic_handler_admin_lib) \
$(dynamic_handler_dirlist_lib) \
-$(dynamic_handler_scgi_lib) \
+$(dynamic_handler_cgi_lib) \
$(dynamic_handler_fcgi_lib) \
+$(dynamic_handler_scgi_lib) \
+$(dynamic_handler_proxy_lib) \
$(dynamic_handler_uwsgi_lib) \
-$(dynamic_handler_fastcgi_lib) \
$(dynamic_handler_redir_lib) \
-$(dynamic_handler_proxy_lib) \
$(dynamic_handler_ssi_lib) \
$(dynamic_handler_secdownload_lib) \
$(dynamic_handler_empty_gif_lib) \
@@ -1661,6 +1660,7 @@ $(dynamic_handler_error_redir_lib) \
$(dynamic_handler_error_nn_lib) \
$(dynamic_handler_common_lib) \
$(dynamic_handler_dbslayer_lib) \
+$(dynamic_handler_admin_lib) \
$(dynamic_encoder_gzip_lib) \
$(dynamic_encoder_deflate_lib) \
$(dynamic_logger_ncsa_lib) \
@@ -1677,6 +1677,8 @@ $(dynamic_cryptor_libssl_lib) \
$(dynamic_balancer_round_robin_lib) \
$(dynamic_balancer_ip_hash_lib)
+#$(dynamic_handler_fastcgi_lib)
+
#
# Cherokee server worker
View
@@ -29,21 +29,20 @@
#include "util.h"
#include "buffer.h"
-#include "downloader_async.h"
+#include "downloader.h"
#include "downloader-protected.h"
+#include "downloader_async.h"
#define ENTRIES "admin,client"
struct cherokee_admin_client {
cherokee_downloader_async_t *downloader;
+ cherokee_fdpoll_t *poll_ref;
cherokee_buffer_t *url_ref;
cherokee_buffer_t request;
cherokee_buffer_t reply;
-
- cherokee_post_t post;
- cherokee_fdpoll_t *poll_ref;
};
#define strcmp_begin(line,sub) strncmp(line, sub, strlen(sub))
@@ -60,7 +59,6 @@ cherokee_admin_client_new (cherokee_admin_client_t **admin)
n->poll_ref = NULL;
n->url_ref = NULL;
- cherokee_post_init (&n->post);
cherokee_downloader_async_new (&n->downloader);
cherokee_buffer_init (&n->request);
cherokee_buffer_init (&n->reply);
@@ -196,19 +194,15 @@ internal_step (cherokee_admin_client_t *admin)
static void
prepare_and_set_post (cherokee_admin_client_t *admin, const char *str, cuint_t str_len)
{
- size_t written;
-
cherokee_downloader_t *downloader = DOWNLOADER(admin->downloader);
cherokee_downloader_set_url (downloader, admin->url_ref);
cherokee_buffer_add (&admin->request, str, str_len);
- /* Build and set the post object
+ /* Copy the post info
*/
- cherokee_post_init (&admin->post);
- cherokee_post_set_len (&admin->post, str_len);
- cherokee_post_append (&admin->post, str, str_len, &written);
- cherokee_downloader_post_set (downloader, &admin->post);
+ cherokee_buffer_clean (&downloader->post);
+ cherokee_buffer_add (&downloader->post, str, str_len);
}
#define SET_POST(admin,str) \
@@ -262,7 +256,7 @@ common_processing (cherokee_admin_client_t *admin,
/* Initial state: needs to get the Post info
*/
if ((downloader->phase == downloader_phase_init) &&
- (downloader->post == NULL))
+ (cherokee_buffer_is_empty (&downloader->post)))
{
conf_request_func (admin, argument);
return ret_eagain;
@@ -74,9 +74,9 @@ typedef enum {
phase_tls_handshake,
phase_reading_header,
phase_processing_header,
- phase_read_post,
phase_setup_connection,
phase_init,
+ phase_read_post,
phase_add_headers,
phase_send_headers,
phase_steping,
@@ -257,7 +257,7 @@ ret_t cherokee_connection_send (cherokee_connection_t *conn);
ret_t cherokee_connection_send_header (cherokee_connection_t *conn);
ret_t cherokee_connection_send_header_and_mmaped (cherokee_connection_t *conn);
ret_t cherokee_connection_send_switching (cherokee_connection_t *conn);
-ret_t cherokee_connection_recv (cherokee_connection_t *conn, cherokee_buffer_t *buffer, off_t *len);
+ret_t cherokee_connection_recv (cherokee_connection_t *conn, cherokee_buffer_t *buffer, off_t to_read, off_t *len);
/* Internal
*/
@@ -283,6 +283,7 @@ ret_t cherokee_connection_step (cherokee_connection_t *conn);
/* Headers
*/
+ret_t cherokee_connection_read_post (cherokee_connection_t *conn);
ret_t cherokee_connection_build_header (cherokee_connection_t *conn);
ret_t cherokee_connection_get_request (cherokee_connection_t *conn);
ret_t cherokee_connection_parse_range (cherokee_connection_t *conn);
View
@@ -299,7 +299,7 @@ cherokee_connection_clean (cherokee_connection_t *conn)
conn->polling_fd = -1;
}
- cherokee_post_mrproper (&conn->post);
+ cherokee_post_clean (&conn->post);
cherokee_buffer_mrproper (&conn->encoder_buffer);
cherokee_buffer_clean (&conn->request);
@@ -711,6 +711,17 @@ build_response_header (cherokee_connection_t *conn, cherokee_buffer_t *buffer)
}
+ret_t
+cherokee_connection_read_post (cherokee_connection_t *conn)
+{
+ if (conn->handler->read_post == NULL) {
+ return ret_ok;
+ }
+
+ return cherokee_handler_read_post (conn->handler);
+}
+
+
ret_t
cherokee_connection_build_header (cherokee_connection_t *conn)
{
@@ -907,12 +918,15 @@ cherokee_connection_tx_add (cherokee_connection_t *conn, ssize_t tx)
ret_t
-cherokee_connection_recv (cherokee_connection_t *conn, cherokee_buffer_t *buffer, off_t *len)
+cherokee_connection_recv (cherokee_connection_t *conn,
+ cherokee_buffer_t *buffer,
+ off_t to_read,
+ off_t *len)
{
ret_t ret;
size_t cnt_read = 0;
- ret = cherokee_socket_bufread (&conn->socket, buffer, DEFAULT_RECV_SIZE, &cnt_read);
+ ret = cherokee_socket_bufread (&conn->socket, buffer, to_read, &cnt_read);
switch (ret) {
case ret_ok:
cherokee_connection_rx_add (conn, cnt_read);
@@ -1712,98 +1726,6 @@ get_range (cherokee_connection_t *conn, char *ptr, int ptr_len)
}
-static ret_t
-send_100continue (cherokee_connection_t *conn)
-{
- ret_t ret;
- const char *reply = "HTTP/1.1 100 Continue" CRLF CRLF; /* 25 chars */
- size_t written = 0;
-
- ret = cherokee_socket_write (&conn->socket, reply, 25, &written);
- if ((ret == ret_ok) && (written == 25)) {
- TRACE(ENTRIES, "Sent a '100 Continue' response.\n");
- return ret_ok;
- }
-
- TRACE(ENTRIES, "Could not send a '100 Continue' response. Error=500.\n");
- conn->error_code = http_internal_error;
- return ret_error;
-}
-
-
-static ret_t
-post_init (cherokee_connection_t *conn)
-{
- ret_t ret;
- off_t post_len;
- char *info = NULL;
- cuint_t info_len = 0;
- CHEROKEE_TEMP(buf, 64);
-
- /* RFC 2616:
- *
- * If a message is received with both a Transfer-Encoding
- * header field and a Content-Length header field, the latter
- * MUST be ignored.
- */
-
- /* Check "Transfer-Encoding"
- */
- ret = cherokee_header_get_known (&conn->header, header_transfer_encoding, &info, &info_len);
- if (ret == ret_ok) {
- if (strncasecmp (info, "chunked", MIN(info_len, 7)) == 0) {
- cherokee_post_set_encoding (&conn->post, post_enc_chunked);
- return ret_ok;
- }
- }
-
- /* Check "Content-Length"
- */
- ret = cherokee_header_get_known (&conn->header, header_content_length, &info, &info_len);
- if (unlikely (ret != ret_ok)) {
- conn->error_code = http_length_required;
- return ret_error;
- }
-
- /* Parse the POST length
- */
- if (unlikely ((info == NULL) ||
- (info_len == 0) ||
- (info_len >= buf_size)))
- {
- conn->error_code = http_bad_request;
- return ret_error;
- }
-
- memcpy (buf, info, info_len);
- buf[info_len] = '\0';
-
- /* Check: Post length >= 0
- */
- post_len = (off_t) atoll(buf);
- if (unlikely (post_len < 0)) {
- conn->error_code = http_bad_request;
- return ret_error;
- }
-
- /* Set the length
- */
- cherokee_post_set_len (&conn->post, post_len);
-
- /* Check "Expect: 100-continue" header
- */
- ret = cherokee_header_get_known (&conn->header, header_expect, &info, &info_len);
- if (ret == ret_ok) {
- ret = send_100continue(conn);
- if (ret != ret_ok) {
- return ret_error;
- }
- }
-
- return ret_ok;
-}
-
-
static ret_t
parse_userdir (cherokee_connection_t *conn)
{
@@ -1863,34 +1785,14 @@ cherokee_connection_get_request (cherokee_connection_t *conn)
if (unlikely (ret < ret_ok))
goto error;
- /* Maybe read the POST data
+ /* Init the POST structure if needed
*/
- if (http_method_with_input (conn->header.method)) {
- uint32_t header_len;
- uint32_t post_len;
- size_t written;
-
- /* Init the post info
- */
- ret = post_init (conn);
+ if (http_method_with_input (conn->header.method))
+ {
+ ret = cherokee_post_read_header (&conn->post, conn);
if (unlikely (ret != ret_ok)) {
return ret;
}
-
- /* Split header and post
- */
- ret = cherokee_header_get_length (&conn->header, &header_len);
- if (unlikely(ret != ret_ok))
- return ret;
-
- post_len = conn->incoming_header.len - header_len;
-
- if (post_len > 0) {
- cherokee_post_append (&conn->post, conn->incoming_header.buf + header_len,
- post_len, &written);
-
- cherokee_buffer_remove_chunk (&conn->incoming_header, header_len, written);
- }
}
/* Copy the request and query string
@@ -1997,7 +1899,7 @@ cherokee_connection_get_request (cherokee_connection_t *conn)
/* Check Upload limit
*/
if ((CONN_VSRV(conn)->post_max_len > 0) &&
- (conn->post.size > CONN_VSRV(conn)->post_max_len))
+ (conn->post.len > CONN_VSRV(conn)->post_max_len))
{
conn->error_code = http_request_entity_too_large;
return ret_error;
@@ -54,7 +54,7 @@ struct cherokee_downloader {
cherokee_buffer_t reply_header;
cherokee_buffer_t body;
- cherokee_post_t *post;
+ cherokee_buffer_t post;
cherokee_buffer_t proxy;
cuint_t proxy_port;
Oops, something went wrong.

0 comments on commit 475ecb2

Please sign in to comment.