Repository: trafficserver Updated Branches: refs/heads/master 46156a8d8 -> 4282d3353
Revert "TS-3656: Activating follow redirection in send server response hook does not work for post. This closes #215." This reverts commit 999946e47a90324ff8bfcbb22d40493e89463599. Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/00cb6981 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/00cb6981 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/00cb6981 Branch: refs/heads/master Commit: 00cb6981e1ccad93e963018b7a75075bade32246 Parents: 5defa51 Author: shinrich <[email protected]> Authored: Mon Jul 6 18:33:03 2015 -0500 Committer: shinrich <[email protected]> Committed: Mon Jul 6 18:33:03 2015 -0500 ---------------------------------------------------------------------- proxy/http/HttpSM.cc | 34 +++++++++++++++++++--------------- proxy/http/HttpTunnel.cc | 27 ++++++++++++++++++++++++--- proxy/http/HttpTunnel.h | 7 ++++++- 3 files changed, 49 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/00cb6981/proxy/http/HttpSM.cc ---------------------------------------------------------------------- diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc index cbcc34b..afbdf3a 100644 --- a/proxy/http/HttpSM.cc +++ b/proxy/http/HttpSM.cc @@ -1835,6 +1835,14 @@ HttpSM::state_read_server_response_header(int event, void *data) t_state.transact_return_point = HttpTransact::HandleResponse; t_state.api_next_action = HttpTransact::SM_ACTION_API_READ_RESPONSE_HDR; + // if exceeded limit deallocate postdata buffers and disable redirection + if (enable_redirection && (redirection_tries < HttpConfig::m_master.number_of_redirections)) { + ++redirection_tries; + } else { + tunnel.deallocate_redirect_postdata_buffers(); + enable_redirection = false; + } + do_api_callout(); break; case PARSE_CONT: @@ -3155,6 +3163,7 @@ HttpSM::tunnel_handler_ua(int event, HttpTunnelConsumer *c) ink_assert(ua_entry->vc == c->vc); if (close_connection) { // If the client could be pipelining, we need to set the ua_session into half close mode + if (t_state.client_info.pipeline_possible == true && c->producer->vc_type != HT_STATIC && event == VC_EVENT_WRITE_COMPLETE) { ua_session->set_half_close_flag(); } @@ -3404,6 +3413,8 @@ HttpSM::tunnel_handler_for_partial_post(int event, void * /* data ATS_UNUSED */) tunnel.deallocate_buffers(); tunnel.reset(); + tunnel.allocate_redirect_postdata_producer_buffer(); + t_state.redirect_info.redirect_in_process = false; if (post_failed) { @@ -5316,20 +5327,17 @@ HttpSM::do_setup_post_tunnel(HttpVC_t to_vc_type) // if redirect_in_process and redirection is enabled add static producer if (t_state.redirect_info.redirect_in_process && enable_redirection && - (tunnel.postbuf && tunnel.postbuf->postdata_copy_buffer_start != NULL)) { + (tunnel.postbuf && tunnel.postbuf->postdata_copy_buffer_start != NULL && tunnel.postbuf->postdata_producer_buffer != NULL)) { post_redirect = true; // copy the post data into a new producer buffer for static producer - int64_t alloc_index = buffer_size_to_index(t_state.hdr_info.request_content_length); - MIOBuffer *postdata_producer_buffer = new_MIOBuffer(alloc_index); - IOBufferReader *postdata_producer_reader = postdata_producer_buffer->alloc_reader(); - postdata_producer_buffer->write(tunnel.postbuf->postdata_copy_buffer_start); - int64_t post_bytes = postdata_producer_reader->read_avail(); + tunnel.postbuf->postdata_producer_buffer->write(tunnel.postbuf->postdata_copy_buffer_start); + int64_t post_bytes = tunnel.postbuf->postdata_producer_reader->read_avail(); transfered_bytes = post_bytes; - p = tunnel.add_producer(HTTP_TUNNEL_STATIC_PRODUCER, post_bytes, postdata_producer_reader, (HttpProducerHandler)NULL, HT_STATIC, - "redirect static agent post"); + p = tunnel.add_producer(HTTP_TUNNEL_STATIC_PRODUCER, post_bytes, tunnel.postbuf->postdata_producer_reader, + (HttpProducerHandler)NULL, HT_STATIC, "redirect static agent post"); // the tunnel has taken over the buffer and will free it - postdata_producer_buffer = NULL; - postdata_producer_reader = NULL; + tunnel.postbuf->postdata_producer_buffer = NULL; + tunnel.postbuf->postdata_producer_reader = NULL; } else { int64_t alloc_index; // content length is undefined, use default buffer size @@ -5358,8 +5366,6 @@ HttpSM::do_setup_post_tunnel(HttpVC_t to_vc_type) ua_buffer_reader->consume(client_request_body_bytes); p = tunnel.add_producer(ua_entry->vc, post_bytes - transfered_bytes, buf_start, &HttpSM::tunnel_handler_post_ua, HT_HTTP_CLIENT, "user agent post"); - post_buffer = NULL; - buf_start = NULL; } ua_entry->in_tunnel = true; @@ -7309,10 +7315,8 @@ void HttpSM::do_redirect() { DebugSM("http_redirect", "[HttpSM::do_redirect]"); - // if exceeded limit deallocate postdata buffers and disable redirection - if (!enable_redirection || (redirection_tries++ >= HttpConfig::m_master.number_of_redirections)) { + if (!enable_redirection || redirection_tries >= HttpConfig::m_master.number_of_redirections) { tunnel.deallocate_redirect_postdata_buffers(); - enable_redirection = false; return; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/00cb6981/proxy/http/HttpTunnel.cc ---------------------------------------------------------------------- diff --git a/proxy/http/HttpTunnel.cc b/proxy/http/HttpTunnel.cc index 571d512..c5eb009 100644 --- a/proxy/http/HttpTunnel.cc +++ b/proxy/http/HttpTunnel.cc @@ -920,9 +920,9 @@ HttpTunnel::producer_run(HttpTunnelProducer *p) } // YTS Team, yamsat Plugin - // Allocate and copy partial POST data to buffers for possible later use in redirect. - // Check for the various parameters including the maximum configured post data size - if (p->alive && sm->t_state.method == HTTP_WKSIDX_POST && (p->vc_type == HT_HTTP_CLIENT)) { + // Allocate and copy partial POST data to buffers. Check for the various parameters + // including the maximum configured post data size + if (p->alive && sm->t_state.method == HTTP_WKSIDX_POST && sm->enable_redirection && (p->vc_type == HT_HTTP_CLIENT)) { Debug("http_redirect", "[HttpTunnel::producer_run] client post: %" PRId64 " max size: %" PRId64 "", p->buffer_start->read_avail(), HttpConfig::m_master.post_copy_size); @@ -1622,6 +1622,19 @@ HttpTunnel::copy_partial_post_data() } // YTS Team, yamsat Plugin +// Allocate a new buffer for static producers +void +HttpTunnel::allocate_redirect_postdata_producer_buffer() +{ + int64_t alloc_index = buffer_size_to_index(sm->t_state.hdr_info.request_content_length); + + ink_release_assert(postbuf->postdata_producer_buffer == NULL); + + postbuf->postdata_producer_buffer = new_MIOBuffer(alloc_index); + postbuf->postdata_producer_reader = postbuf->postdata_producer_buffer->alloc_reader(); +} + +// YTS Team, yamsat Plugin // Allocating the post data buffers void HttpTunnel::allocate_redirect_postdata_buffers(IOBufferReader *ua_reader) @@ -1637,10 +1650,13 @@ HttpTunnel::allocate_redirect_postdata_buffers(IOBufferReader *ua_reader) postbuf->ua_buffer_reader = ua_reader; postbuf->postdata_copy_buffer = new_MIOBuffer(alloc_index); postbuf->postdata_copy_buffer_start = postbuf->postdata_copy_buffer->alloc_reader(); + allocate_redirect_postdata_producer_buffer(); } else { // Reset the buffer readers postbuf->postdata_copy_buffer->dealloc_reader(postbuf->postdata_copy_buffer_start); postbuf->postdata_copy_buffer_start = postbuf->postdata_copy_buffer->alloc_reader(); + postbuf->postdata_producer_buffer->dealloc_reader(postbuf->postdata_producer_reader); + postbuf->postdata_producer_reader = postbuf->postdata_producer_buffer->alloc_reader(); } } @@ -1653,6 +1669,11 @@ HttpTunnel::deallocate_redirect_postdata_buffers() Debug("http_redirect", "[HttpTunnel::deallocate_postdata_copy_buffers]"); if (postbuf != NULL) { + if (postbuf->postdata_producer_buffer != NULL) { + free_MIOBuffer(postbuf->postdata_producer_buffer); + postbuf->postdata_producer_buffer = NULL; + postbuf->postdata_producer_reader = NULL; // deallocated by the buffer + } if (postbuf->postdata_copy_buffer != NULL) { free_MIOBuffer(postbuf->postdata_copy_buffer); postbuf->postdata_copy_buffer = NULL; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/00cb6981/proxy/http/HttpTunnel.h ---------------------------------------------------------------------- diff --git a/proxy/http/HttpTunnel.h b/proxy/http/HttpTunnel.h index 3bfac74..db760a6 100644 --- a/proxy/http/HttpTunnel.h +++ b/proxy/http/HttpTunnel.h @@ -260,12 +260,16 @@ struct HttpTunnelProducer { class PostDataBuffers { public: - PostDataBuffers() : postdata_copy_buffer(NULL), postdata_copy_buffer_start(NULL), ua_buffer_reader(NULL) + PostDataBuffers() + : postdata_producer_buffer(NULL), postdata_copy_buffer(NULL), postdata_producer_reader(NULL), postdata_copy_buffer_start(NULL), + ua_buffer_reader(NULL) { Debug("http_redirect", "[PostDataBuffers::PostDataBuffers]"); } + MIOBuffer *postdata_producer_buffer; MIOBuffer *postdata_copy_buffer; + IOBufferReader *postdata_producer_reader; IOBufferReader *postdata_copy_buffer_start; IOBufferReader *ua_buffer_reader; }; @@ -310,6 +314,7 @@ public: // YTS Team, yamsat Plugin void copy_partial_post_data(); + void allocate_redirect_postdata_producer_buffer(); void allocate_redirect_postdata_buffers(IOBufferReader *ua_reader); void deallocate_redirect_postdata_buffers();
