@@ -1913,8 +1913,7 @@ HttpSM::state_read_server_response_header(int event, void *data)
19131913 if (enable_redirection && (redirection_tries <= t_state.txn_conf ->number_of_redirections )) {
19141914 ++redirection_tries;
19151915 } else {
1916- tunnel.deallocate_redirect_postdata_buffers ();
1917- enable_redirection = false ;
1916+ this ->disable_redirect ();
19181917 }
19191918
19201919 do_api_callout ();
@@ -2693,7 +2692,7 @@ HttpSM::tunnel_handler_cache_fill(int event, void *data)
26932692 ink_release_assert (cache_sm.cache_write_vc );
26942693
26952694 tunnel.deallocate_buffers ();
2696- tunnel. deallocate_redirect_postdata_buffers ();
2695+ this -> postbuf_clear ();
26972696 tunnel.reset ();
26982697
26992698 setup_server_transfer_to_cache_only ();
@@ -2720,7 +2719,7 @@ HttpSM::tunnel_handler_100_continue(int event, void *data)
27202719 // does not free the memory from the header
27212720 t_state.hdr_info .client_response .destroy ();
27222721 tunnel.deallocate_buffers ();
2723- tunnel. deallocate_redirect_postdata_buffers ();
2722+ this -> postbuf_clear ();
27242723 tunnel.reset ();
27252724
27262725 if (server_entry->eos ) {
@@ -2771,7 +2770,7 @@ HttpSM::tunnel_handler_push(int event, void *data)
27712770 // Reset tunneling state since we need to send a response
27722771 // to client as whether we succeeded
27732772 tunnel.deallocate_buffers ();
2774- tunnel. deallocate_redirect_postdata_buffers ();
2773+ this -> postbuf_clear ();
27752774 tunnel.reset ();
27762775
27772776 if (cache_write_success) {
@@ -3462,8 +3461,6 @@ HttpSM::tunnel_handler_for_partial_post(int event, void * /* data ATS_UNUSED */)
34623461 tunnel.deallocate_buffers ();
34633462 tunnel.reset ();
34643463
3465- tunnel.allocate_redirect_postdata_producer_buffer ();
3466-
34673464 t_state.redirect_info .redirect_in_process = false ;
34683465
34693466 if (post_failed) {
@@ -5258,8 +5255,7 @@ HttpSM::handle_post_failure()
52585255
52595256 // disable redirection in case we got a partial response and then EOS, because the buffer might not
52605257 // have the full post and it's deallocating the post buffers here
5261- enable_redirection = false ;
5262- tunnel.deallocate_redirect_postdata_buffers ();
5258+ this ->disable_redirect ();
52635259
52645260 // Don't even think about doing keep-alive after this debacle
52655261 t_state.client_info .keep_alive = HTTP_NO_KEEPALIVE;
@@ -5526,19 +5522,17 @@ HttpSM::do_setup_post_tunnel(HttpVC_t to_vc_type)
55265522 // YTS Team, yamsat Plugin
55275523 // if redirect_in_process and redirection is enabled add static producer
55285524
5529- if (t_state.redirect_info .redirect_in_process && enable_redirection &&
5530- (tunnel.postbuf && tunnel.postbuf ->postdata_copy_buffer_start != nullptr &&
5531- tunnel.postbuf ->postdata_producer_buffer != nullptr )) {
5525+ if (t_state.redirect_info .redirect_in_process && enable_redirection && (this ->_postbuf .postdata_copy_buffer_start != nullptr )) {
55325526 post_redirect = true ;
55335527 // copy the post data into a new producer buffer for static producer
5534- tunnel.postbuf ->postdata_producer_buffer ->write (tunnel.postbuf ->postdata_copy_buffer_start );
5535- int64_t post_bytes = tunnel.postbuf ->postdata_producer_reader ->read_avail ();
5528+ MIOBuffer *postdata_producer_buffer = new_empty_MIOBuffer ();
5529+ IOBufferReader *postdata_producer_reader = postdata_producer_buffer->alloc_reader ();
5530+
5531+ postdata_producer_buffer->write (this ->_postbuf .postdata_copy_buffer_start );
5532+ int64_t post_bytes = postdata_producer_reader->read_avail ();
55365533 transfered_bytes = post_bytes;
5537- p = tunnel.add_producer (HTTP_TUNNEL_STATIC_PRODUCER, post_bytes, tunnel.postbuf ->postdata_producer_reader ,
5538- (HttpProducerHandler) nullptr , HT_STATIC, " redirect static agent post" );
5539- // the tunnel has taken over the buffer and will free it
5540- tunnel.postbuf ->postdata_producer_buffer = nullptr ;
5541- tunnel.postbuf ->postdata_producer_reader = nullptr ;
5534+ p = tunnel.add_producer (HTTP_TUNNEL_STATIC_PRODUCER, post_bytes, postdata_producer_reader, (HttpProducerHandler) nullptr ,
5535+ HT_STATIC, " redirect static agent post" );
55425536 } else {
55435537 int64_t alloc_index;
55445538 // content length is undefined, use default buffer size
@@ -5554,6 +5548,10 @@ HttpSM::do_setup_post_tunnel(HttpVC_t to_vc_type)
55545548 IOBufferReader *buf_start = post_buffer->alloc_reader ();
55555549 int64_t post_bytes = chunked ? INT64_MAX : t_state.hdr_info .request_content_length ;
55565550
5551+ if (enable_redirection) {
5552+ this ->_postbuf .init (post_buffer->clone_reader (buf_start));
5553+ }
5554+
55575555 // Note: Many browsers, Netscape and IE included send two extra
55585556 // bytes (CRLF) at the end of the post. We just ignore those
55595557 // bytes since the sending them is not spec
@@ -6695,7 +6693,7 @@ void
66956693HttpSM::kill_this ()
66966694{
66976695 ink_release_assert (reentrancy_count == 1 );
6698- tunnel. deallocate_redirect_postdata_buffers ();
6696+ this -> postbuf_clear ();
66996697 enable_redirection = false ;
67006698
67016699 if (kill_this_async_done == false ) {
@@ -7599,7 +7597,7 @@ HttpSM::do_redirect()
75997597{
76007598 DebugSM (" http_redirect" , " [HttpSM::do_redirect]" );
76017599 if (!enable_redirection || redirection_tries > t_state.txn_conf ->number_of_redirections ) {
7602- tunnel. deallocate_redirect_postdata_buffers ();
7600+ this -> postbuf_clear ();
76037601 return ;
76047602 }
76057603
@@ -7988,3 +7986,51 @@ HttpSM::find_proto_string(HTTPVersion version) const
79887986 }
79897987 return nullptr ;
79907988}
7989+
7990+ // YTS Team, yamsat Plugin
7991+ // Function to copy the partial Post data while tunnelling
7992+ void
7993+ PostDataBuffers::copy_partial_post_data ()
7994+ {
7995+ this ->postdata_copy_buffer ->write (this ->ua_buffer_reader );
7996+ Debug (" http_redirect" , " [PostDataBuffers::copy_partial_post_data] wrote %" PRId64 " bytes to buffers %" PRId64 " " ,
7997+ this ->ua_buffer_reader ->read_avail (), this ->postdata_copy_buffer_start ->read_avail ());
7998+ this ->ua_buffer_reader ->consume (this ->ua_buffer_reader ->read_avail ());
7999+ }
8000+
8001+ // YTS Team, yamsat Plugin
8002+ // Allocating the post data buffers
8003+ void
8004+ PostDataBuffers::init (IOBufferReader *ua_reader)
8005+ {
8006+ Debug (" http_redirect" , " [PostDataBuffers::init]" );
8007+
8008+ this ->ua_buffer_reader = ua_reader;
8009+
8010+ if (this ->postdata_copy_buffer == nullptr ) {
8011+ ink_assert (this ->postdata_copy_buffer_start == nullptr );
8012+ this ->postdata_copy_buffer = new_empty_MIOBuffer (BUFFER_SIZE_INDEX_4K);
8013+ this ->postdata_copy_buffer_start = this ->postdata_copy_buffer ->alloc_reader ();
8014+ }
8015+
8016+ ink_assert (this ->ua_buffer_reader != nullptr );
8017+ }
8018+
8019+ // YTS Team, yamsat Plugin
8020+ // Deallocating the post data buffers
8021+ void
8022+ PostDataBuffers::clear ()
8023+ {
8024+ Debug (" http_redirect" , " [PostDataBuffers::clear]" );
8025+
8026+ if (this ->postdata_copy_buffer != nullptr ) {
8027+ free_MIOBuffer (this ->postdata_copy_buffer );
8028+ this ->postdata_copy_buffer = nullptr ;
8029+ this ->postdata_copy_buffer_start = nullptr ; // deallocated by the buffer
8030+ }
8031+ }
8032+
8033+ PostDataBuffers::~PostDataBuffers ()
8034+ {
8035+ this ->clear ();
8036+ }
0 commit comments