不cache包含Set-cookie的应答。修改多处日志细节。

This commit is contained in:
zhengchao
2018-10-21 15:03:04 +08:00
parent c94b267a65
commit c5f5ee2655
8 changed files with 36 additions and 9 deletions

View File

@@ -275,6 +275,11 @@ enum cache_pending_action tfe_cache_put_pending(const struct tfe_http_half *resp
{
return FORBIDDEN;
}
value=tfe_http_std_field_read(response, TFE_HTTP_SET_COOKIE);
if(value!=NULL)
{
return FORBIDDEN;
}
value = tfe_http_std_field_read(response, TFE_HTTP_PRAGMA);
if (value != NULL)
{

View File

@@ -137,6 +137,7 @@ enum tfe_http_std_field
TFE_HTTP_REFERER,
TFE_HTTP_USER_AGENT,
TFE_HTTP_COOKIE,
TFE_HTTP_SET_COOKIE,
TFE_HTTP_PROXY_AUTHORIZATION,
TFE_HTTP_AUTHORIZATION,
TFE_HTTP_LOCATION,

View File

@@ -11,6 +11,7 @@ static const char * __str_std_header_field_map[] =
[TFE_HTTP_REFERER] = "Referer",
[TFE_HTTP_USER_AGENT] = "User-Agent",
[TFE_HTTP_COOKIE] = "Cookie",
[TFE_HTTP_SET_COOKIE]="Set-Cookie",
[TFE_HTTP_PROXY_AUTHORIZATION] = "Proxy-Authorization",
[TFE_HTTP_AUTHORIZATION] = "Authorization",
[TFE_HTTP_LOCATION] = "Location",

View File

@@ -4,6 +4,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/prctl.h>
#include <netinet/in.h>
#include <sys/un.h>
#include <assert.h>
@@ -14,6 +15,7 @@
#include <errno.h>
#include <pthread.h>
#include <event2/event.h>
#include <event2/listener.h>
#include <event2/bufferevent.h>
@@ -135,6 +137,7 @@ void tfe_proxy_free(tfe_proxy * ctx)
static void __dummy_event_handler(evutil_socket_t fd, short what, void * arg)
{
printf("%s alive\n",__FUNCTION__);
return;
}
@@ -172,7 +175,7 @@ static void __gc_handler_cb(evutil_socket_t fd, short what, void * arg)
return;
}
static void * __thread_ctx_entry(void * arg)
static void * tfe_work_thread(void * arg)
{
struct tfe_thread_ctx * ctx = (struct tfe_thread_ctx *) arg;
struct timeval timer_delay = {60, 0};
@@ -187,11 +190,15 @@ static void * __thread_ctx_entry(void * arg)
evtimer_add(ev, &timer_delay);
ctx->running = 1;
__currect_thread_id = ctx->thread_id;
char thread_name[16];
snprintf(thread_name, sizeof(thread_name), "tfe:worker%d", ctx->thread_id);
prctl(PR_SET_NAME,(unsigned long long)thread_name,NULL,NULL,NULL);
TFE_LOG_INFO(g_default_logger, "Thread %u is running...", ctx->thread_id);
TFE_LOG_INFO(g_default_logger, "Work thread %u is running...", ctx->thread_id);
event_base_dispatch(ctx->evbase);
assert(0);
event_free(ev);
TFE_LOG_ERROR(g_default_logger, "Work thread %u is exit...", ctx->thread_id);
return (void *)NULL;
}
@@ -215,7 +222,7 @@ int tfe_proxy_work_thread_run(struct tfe_proxy * proxy)
for(i=0; i<proxy->nr_work_threads;i++)
{
__thread_ctx=proxy->work_threads[i];
ret = pthread_create(&__thread_ctx->thr, NULL, __thread_ctx_entry, (void *)__thread_ctx);
ret = pthread_create(&__thread_ctx->thr, NULL, tfe_work_thread, (void *)__thread_ctx);
if (unlikely(ret < 0))
{
TFE_LOG_ERROR(proxy->logger, "Failed at pthread_create() for thread %d, error %d: %s", i, errno, strerror(errno));

View File

@@ -249,7 +249,7 @@ void ssl_stat_init(struct ssl_mgr * mgr)
spec[SSL_DOWN_ERR]="dssl_err";
spec[SSL_DOWN_CLOSING]="dssl_clsing";
spec[SSL_DOWN_CLOSED]="dssl_clsed";
spec[SSL_DOWN_DIRTY_CLOSED]="ssld_dirty_cls";
spec[SSL_DOWN_DIRTY_CLOSED]="dssl_dirty_cls";
spec[SSL_DOWN_CACHE_SZ]="dsess_cache";
spec[SSL_DOWN_CACHE_QUERY]="dcache_query";
spec[SSL_DOWN_CACHE_HIT]="dsess_hitcnt";

View File

@@ -60,6 +60,7 @@ enum pangu_http_stat
STAT_ACTION_MONIT,
STAT_ACTION_REJECT,
STAT_ACTION_REDIRECT,
STAT_ACTION_PRE_REPLACE,
STAT_ACTION_REPLACE,
STAT_ACTION_WHITELSIT,
__PG_STAT_MAX
@@ -185,9 +186,10 @@ static void pangu_http_stat_init(struct pangu_rt * pangu_runtime)
const char* spec[__PG_STAT_MAX]={0};
spec[STAT_SESSION]="http_sess";
spec[STAT_LOG_NUM]="log_num";
spec[STAT_ACTION_MONIT]="monit";
spec[STAT_ACTION_MONIT]="monitor";
spec[STAT_ACTION_REJECT]="reject";
spec[STAT_ACTION_REDIRECT]="redirect";
spec[STAT_ACTION_PRE_REPLACE]="pre_replace";
spec[STAT_ACTION_REPLACE]="replace";
spec[STAT_ACTION_WHITELSIT]="whitelist";
@@ -291,6 +293,7 @@ struct replace_ctx
struct pangu_http_ctx
{
int magic_num;
enum pangu_action action;
char * action_para;
scan_status_t mid;
@@ -329,9 +332,11 @@ void http_repl_ctx_free(struct replace_ctx* rep_ctx)
FREE(&rep_ctx);
return;
}
#define HTTP_CTX_MAGIC_NUM 20181021
static struct pangu_http_ctx * pangu_http_ctx_new(unsigned int thread_id)
{
struct pangu_http_ctx * ctx = ALLOC(struct pangu_http_ctx, 1);
ctx->magic_num=HTTP_CTX_MAGIC_NUM;
ctx->mid = NULL;
ctx->thread_id = (int) thread_id;
return ctx;
@@ -339,6 +344,7 @@ static struct pangu_http_ctx * pangu_http_ctx_new(unsigned int thread_id)
static void pangu_http_ctx_free(struct pangu_http_ctx * ctx)
{
assert(ctx->magic_num==HTTP_CTX_MAGIC_NUM);
if (ctx->rep_ctx)
{
http_repl_ctx_free(ctx->rep_ctx);
@@ -365,6 +371,7 @@ static void pangu_http_ctx_free(struct pangu_http_ctx * ctx)
future_destroy(ctx->f_cache_query);
ctx->f_cache_query=NULL;
}
ctx->magic_num=0;
FREE(&ctx);
}
@@ -912,7 +919,7 @@ void enforce_control_policy(const struct tfe_stream * stream, const struct tfe_h
break;
case PG_ACTION_REPLACE:
http_replace(stream, session, events, body_frag, frag_size, ctx);
ATOMIC_INC(&(g_pangu_rt->stat_val[STAT_ACTION_REPLACE]));
ATOMIC_INC(&(g_pangu_rt->stat_val[STAT_ACTION_PRE_REPLACE]));
break;
case PG_ACTION_WHITELIST:
tfe_http_session_detach(session);
@@ -1018,6 +1025,10 @@ void pangu_on_http_end(const struct tfe_stream * stream,
ret=pangu_send_log(g_pangu_rt->send_logger, &log_msg);
ATOMIC_ADD(&(g_pangu_rt->stat_val[STAT_LOG_NUM]), ret);
}
if(ctx->rep_ctx && ctx->rep_ctx->actually_replaced==0)
{
ATOMIC_INC(&(g_pangu_rt->stat_val[STAT_ACTION_REPLACE]));
}
pangu_http_ctx_free(ctx);
*pme = NULL;
return;

View File

@@ -327,10 +327,11 @@ static void wrap_cache_query_on_succ(future_result_t * result, void * user)
FS_operate(ctx->ref_handle->fs_handle, ctx->ref_handle->fs_id[STAT_CACHE_QUERY_HIT_OJB_SIZE], 0, FS_OP_SET, _result->tlength/1024);
TFE_LOG_DEBUG(ctx->ref_handle->logger, "cache query hit: %s", ctx->url);
break;
case RESULT_TYPE_END:
case RESULT_TYPE_MISS:
//last call.
TFE_LOG_DEBUG(ctx->ref_handle->logger, "cache query miss: %s", ctx->url);
//NOT break intentionally.
case RESULT_TYPE_END:
//last call.
promise_dettach_ctx(p);
cache_query_ctx_free_cb(ctx);
break;

View File

@@ -22,6 +22,7 @@ static const char * __str_std_header_field_map[] =
[TFE_HTTP_REFERER] = "Referer",
[TFE_HTTP_USER_AGENT] = "User-Agent",
[TFE_HTTP_COOKIE] = "Cookie",
[TFE_HTTP_SET_COOKIE] = "Set-Cookie",
[TFE_HTTP_PROXY_AUTHORIZATION] = "Proxy-Authorization",
[TFE_HTTP_AUTHORIZATION] = "Authorization",
[TFE_HTTP_LOCATION] = "Location",