Skip to content

Commit daafeda

Browse files
committed
move the postbuf to HttpSM
1 parent 4015351 commit daafeda

File tree

4 files changed

+144
-159
lines changed

4 files changed

+144
-159
lines changed

proxy/http/HttpSM.cc

Lines changed: 67 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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
66956693
HttpSM::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+
}

proxy/http/HttpSM.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,22 @@ enum HttpPluginTunnel_t {
177177
class CoreUtils;
178178
class PluginVCCore;
179179

180+
class PostDataBuffers
181+
{
182+
public:
183+
PostDataBuffers() { Debug("http_redirect", "[PostDataBuffers::PostDataBuffers]"); }
184+
185+
MIOBuffer *postdata_copy_buffer = nullptr;
186+
IOBufferReader *postdata_copy_buffer_start = nullptr;
187+
IOBufferReader *ua_buffer_reader = nullptr;
188+
189+
void clear();
190+
void init(IOBufferReader *ua_reader);
191+
void copy_partial_post_data();
192+
193+
~PostDataBuffers();
194+
};
195+
180196
class HttpSM : public Continuation
181197
{
182198
friend class HttpPagesHandler;
@@ -296,6 +312,14 @@ class HttpSM : public Continuation
296312

297313
HttpTransact::State t_state;
298314

315+
// _postbuf api
316+
int64_t postbuf_reader_avail();
317+
int64_t postbuf_buffer_avail();
318+
void postbuf_clear();
319+
void disable_redirect();
320+
void postbuf_copy_partial_data();
321+
void postbuf_init(IOBufferReader *ua_reader);
322+
299323
protected:
300324
int reentrancy_count = 0;
301325

@@ -561,6 +585,9 @@ class HttpSM : public Continuation
561585
{
562586
return terminate_sm;
563587
}
588+
589+
private:
590+
PostDataBuffers _postbuf;
564591
};
565592

566593
// Function to get the cache_sm object - YTS Team, yamsat
@@ -659,4 +686,41 @@ HttpSM::is_transparent_passthrough_allowed()
659686
ua_session->get_transact_count() == 1);
660687
}
661688

689+
inline int64_t
690+
HttpSM::postbuf_reader_avail()
691+
{
692+
return this->_postbuf.ua_buffer_reader->read_avail();
693+
}
694+
695+
inline int64_t
696+
HttpSM::postbuf_buffer_avail()
697+
{
698+
return this->_postbuf.postdata_copy_buffer_start->read_avail();
699+
}
700+
701+
inline void
702+
HttpSM::postbuf_clear()
703+
{
704+
this->_postbuf.clear();
705+
}
706+
707+
inline void
708+
HttpSM::disable_redirect()
709+
{
710+
this->enable_redirection = false;
711+
this->_postbuf.clear();
712+
}
713+
714+
inline void
715+
HttpSM::postbuf_copy_partial_data()
716+
{
717+
this->_postbuf.copy_partial_post_data();
718+
}
719+
720+
inline void
721+
HttpSM::postbuf_init(IOBufferReader *ua_reader)
722+
{
723+
this->_postbuf.init(ua_reader);
724+
}
725+
662726
#endif

0 commit comments

Comments
 (0)