Close #33 增加HTTP Upgrade透明转发的功能

This commit is contained in:
Lu Qiuwen
2018-10-24 15:40:26 +08:00
parent c53641bc27
commit 62b8089166
4 changed files with 28 additions and 5 deletions

View File

@@ -236,8 +236,15 @@ void __kni_event_cb(evutil_socket_t fd, short what, void * user)
__cmsghdr = CMSG_FIRSTHDR(&__msghdr); __cmsghdr = CMSG_FIRSTHDR(&__msghdr);
__fds = (int *) (CMSG_DATA(__cmsghdr)); __fds = (int *) (CMSG_DATA(__cmsghdr));
if(__kni_parse_tlv_data(__ctx, &__accept_para, __buffer, (size_t)rd) < 0) if (unlikely(__fds == NULL))
{ {
TFE_LOG_ERROR(__ctx->logger, "Failed at fetch CMSG_DATA() from incoming fds, close KNI connection.");
goto __close_kni_connection;
}
if(unlikely(__kni_parse_tlv_data(__ctx, &__accept_para, __buffer, (size_t)rd) < 0))
{
TFE_LOG_ERROR(__ctx->logger, "Failed at parsing TLV format, close KNI connection.");
goto __close_kni_connection; goto __close_kni_connection;
} }

View File

@@ -92,6 +92,9 @@ struct http_half_private
struct evbuffer * evbuf_body; struct evbuffer * evbuf_body;
struct evbuffer * evbuf_raw; struct evbuffer * evbuf_raw;
struct tfe_stream_write_ctx * write_ctx; struct tfe_stream_write_ctx * write_ctx;
/* UPGRADE */
bool is_upgrade;
}; };
struct http_half_private * hf_private_create(tfe_http_direction ht_dir, short major, short minor); struct http_half_private * hf_private_create(tfe_http_direction ht_dir, short major, short minor);

View File

@@ -436,8 +436,7 @@ enum tfe_stream_action __http_connection_entry_on_response(const struct tfe_stre
hf_private_set_session(hf_private_resp_in, hs_private); hf_private_set_session(hf_private_resp_in, hs_private);
/* Closure, catch stream, session and thread_id */ /* Closure, catch stream, session and thread_id */
struct user_event_dispatch_closure * __closure = ALLOC( struct user_event_dispatch_closure * __closure = ALLOC(struct user_event_dispatch_closure, 1);
struct user_event_dispatch_closure, 1);
__closure->thread_id = thread_id; __closure->thread_id = thread_id;
__closure->stream = stream; __closure->stream = stream;
__closure->session = to_hs_public(hs_private); __closure->session = to_hs_public(hs_private);
@@ -478,6 +477,13 @@ enum tfe_stream_action __http_connection_entry_on_response(const struct tfe_stre
goto __errout; goto __errout;
} }
/* Upgrade, passthrough the connection and close this session */
if (hf_private_resp_in->is_upgrade)
{
tfe_stream_detach(stream);
hf_private_resp_in->stream_action = ACTION_FORWARD_DATA;
}
hf_private_resp_user = hs_private->hf_private_resp_user; hf_private_resp_user = hs_private->hf_private_resp_user;
if (hf_private_resp_user != NULL) if (hf_private_resp_user != NULL)
{ {

View File

@@ -775,6 +775,11 @@ int hf_private_parse(struct http_half_private * hf_private, const unsigned char
__is_paused = true; __is_paused = true;
} }
if (hf_private->parse_object->upgrade)
{
hf_private->is_upgrade = true;
}
if (sz_parsed == __len_with_offset) if (sz_parsed == __len_with_offset)
{ {
hf_private->parse_cursor += sz_parsed; hf_private->parse_cursor += sz_parsed;
@@ -1091,10 +1096,12 @@ void __write_access_log(struct http_session_private * hs_private)
const char * __str_cont_length = resp_spec ? resp_spec->content_length : "-"; const char * __str_cont_length = resp_spec ? resp_spec->content_length : "-";
/* Content Encoding */ /* Content Encoding */
const char * __str_cont_encoding = resp_spec ? resp_spec->content_encoding : "-"; const char * __str_cont_encoding = resp_spec ? resp_spec->content_encoding : "-";
/* Upgrade Tag */
const char * __str_upgrade = response->is_upgrade ? "UPGRADE" : "-";
char * __access_log; char * __access_log;
asprintf(&__access_log, "%s %s %s %s %s %s", __str_method, asprintf(&__access_log, "%s %s %s %s %s %s %s", __str_method,
__str_url, __str_resp_code, __str_cont_type, __str_cont_length, __str_cont_encoding); __str_url, __str_resp_code, __str_cont_type, __str_cont_length, __str_cont_encoding, __str_upgrade);
const struct tfe_stream * stream = hs_private->hc_private->stream; const struct tfe_stream * stream = hs_private->hc_private->stream;
tfe_stream_write_access_log(stream, RLOG_LV_INFO, "%s", __access_log); tfe_stream_write_access_log(stream, RLOG_LV_INFO, "%s", __access_log);