Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions proxy/ProxySession.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <string_view>
#include "P_Net.h"
#include "InkAPIInternal.h"
#include "http/Http1ServerSession.h"
#include "http/HttpSessionAccept.h"
#include "IPAllow.h"

Expand All @@ -39,6 +38,12 @@
#define SsnDebug(ssn, tag, ...) SpecificDebug((ssn)->debug(), tag, __VA_ARGS__)

class ProxyTransaction;
class Http1ServerSession; // TODO: refactor

enum {
HTTP_MAGIC_ALIVE = 0x0123FEED,
HTTP_MAGIC_DEAD = 0xDEADFEED,
};

enum class ProxyErrorClass {
NONE,
Expand Down Expand Up @@ -86,7 +91,7 @@ class ProxySession : public VConnection
// Virtual Methods
virtual void new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOBufferReader *reader) = 0;
virtual void start() = 0;
virtual void attach_server_session(Http1ServerSession *ssession, bool transaction_done = true);
virtual void attach_server_session(Http1ServerSession *ssession, bool transaction_done = true); // TODO: refactor

virtual void release(ProxyTransaction *trans) = 0;

Expand All @@ -108,7 +113,7 @@ class ProxySession : public VConnection
virtual void set_half_close_flag(bool flag);
virtual bool get_half_close_flag() const;

virtual Http1ServerSession *get_server_session() const;
virtual Http1ServerSession *get_server_session() const; // TODO: refactor

// Replicate NetVConnection API
virtual sockaddr const *get_client_addr();
Expand Down
2 changes: 1 addition & 1 deletion proxy/http/Http1ClientSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class Http1ClientSession : public ProxySession
};

NetVConnection *client_vc = nullptr;
int magic = HTTP_SS_MAGIC_DEAD;
int magic = HTTP_MAGIC_DEAD;
int transact_count = 0;
bool half_close = false;
bool conn_decrease = false;
Expand Down
10 changes: 8 additions & 2 deletions proxy/http/Http1ServerSession.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Http1ServerSession::destroy()
ink_release_assert(server_vc == nullptr);
ink_assert(read_buffer);
ink_assert(server_trans_stat == 0);
magic = HTTP_SS_MAGIC_DEAD;
magic = HTTP_MAGIC_DEAD;
if (read_buffer) {
free_MIOBuffer(read_buffer);
read_buffer = nullptr;
Expand All @@ -71,7 +71,7 @@ Http1ServerSession::new_connection(NetVConnection *new_vc)
// Unique client session identifier.
con_id = ink_atomic_increment((&next_ss_id), 1);

magic = HTTP_SS_MAGIC_ALIVE;
magic = HTTP_MAGIC_ALIVE;
HTTP_SUM_GLOBAL_DYN_STAT(http_current_server_connections_stat, 1); // Update the true global stat
HTTP_INCREMENT_DYN_STAT(http_total_server_connections_stat);

Expand Down Expand Up @@ -243,3 +243,9 @@ Http1ServerSession::protocol_contains(std::string_view tag_prefix) const
auto vc = this->get_netvc();
return vc ? vc->protocol_contains(tag_prefix) : nullptr;
}

const char *
Http1ServerSession::get_protocol_string() const
{
return "http";
};
72 changes: 59 additions & 13 deletions proxy/http/Http1ServerSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include "HttpConnectionCount.h"
#include "HttpProxyAPIEnums.h"
#include "ProxySession.h"

class HttpSM;
class MIOBuffer;
Expand All @@ -48,27 +49,23 @@ enum HSS_State {
HSS_KA_SHARED,
};

enum {
HTTP_SS_MAGIC_ALIVE = 0x0123FEED,
HTTP_SS_MAGIC_DEAD = 0xDEADFEED,
};

class Http1ServerSession : public VConnection
class Http1ServerSession : public ProxySession
{
using self_type = Http1ServerSession;
using super_type = VConnection;
using super_type = ProxySession;

public:
Http1ServerSession() : super_type(nullptr) {}
Http1ServerSession() : super_type() {}
Http1ServerSession(self_type const &) = delete;
self_type &operator=(self_type const &) = delete;

////////////////////
// Methods
void new_connection(NetVConnection *new_vc);
void release();
void destroy();
void destroy() override;

////////////////////
// VConnection Methods
VIO *do_io_read(Continuation *c, int64_t nbytes = INT64_MAX, MIOBuffer *buf = nullptr) override;
VIO *do_io_write(Continuation *c = nullptr, int64_t nbytes = INT64_MAX, IOBufferReader *buf = nullptr,
Expand All @@ -77,15 +74,64 @@ class Http1ServerSession : public VConnection
void do_io_shutdown(ShutdownHowTo_t howto) override;

void reenable(VIO *vio) override;
void
new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOBufferReader *reader) override
{
// TODO: refactor this
ink_assert(0);
}
void
start() override
{
// TODO: refactor this
ink_assert(0);
}
void
attach_server_session(Http1ServerSession *ssession, bool transaction_done = true) override
{
// TODO: refactor this
ink_assert(0);
}
void
release(ProxyTransaction *trans) override
{
// TODO: refactor this
ink_assert(0);
}

void
increment_current_active_client_connections_stat() override
{
// TODO: refactor this
ink_assert(0);
}
void
decrement_current_active_client_connections_stat() override
{
// TODO: refactor this
ink_assert(0);
}

////////////////////
// Virtual Accessors
int
get_transact_count() const override
{
// TODO: refactor this
return transact_count;
}
const char *get_protocol_string() const override;

////////////////////
// Accessors
NetVConnection *get_netvc() const override;
const char *protocol_contains(std::string_view tag_prefix) const override;
int populate_protocol(std::string_view *result, int size) const override;
void enable_outbound_connection_tracking(OutboundConnTrack::Group *group);
IOBufferReader *get_reader();
void attach_hostname(const char *hostname);
NetVConnection *get_netvc() const;
void set_netvc(NetVConnection *new_vc);
IpEndpoint const &get_server_ip() const;
int populate_protocol(std::string_view *result, int size) const;
const char *protocol_contains(std::string_view tag_prefix) const;

////////////////////
// Variables
Expand Down Expand Up @@ -156,7 +202,7 @@ class Http1ServerSession : public VConnection

private:
NetVConnection *server_vc = nullptr;
int magic = HTTP_SS_MAGIC_DEAD;
int magic = HTTP_MAGIC_DEAD;

IOBufferReader *buf_reader = nullptr;
};
Expand Down
3 changes: 2 additions & 1 deletion proxy/http/HttpTransactHeaders.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "HdrUtils.h"
#include "HttpCompat.h"
#include "HttpSM.h"
#include "Http1ServerSession.h"

#include "I_Machine.h"

Expand Down Expand Up @@ -883,7 +884,7 @@ HttpTransactHeaders::insert_via_header_in_response(HttpTransact::State *s, HTTPH
// Should suffice - if we're adding a response VIA, the connection is HTTP and only 1.0 and 1.1 are supported outbound.
proto_buf[n_proto++] = HTTP_MINOR(header->version_get().m_version) == 0 ? IP_PROTO_TAG_HTTP_1_0 : IP_PROTO_TAG_HTTP_1_1;

auto ss = s->state_machine->get_server_session();
Http1ServerSession *ss = s->state_machine->get_server_session();
if (ss) {
n_proto += ss->populate_protocol(proto_buf.data() + n_proto, proto_buf.size() - n_proto);
}
Expand Down