Added simple accesslog
This commit is contained in:
parent
b7335a949f
commit
4bc200f9dc
|
@ -88,6 +88,7 @@ shrpx_SOURCES = ${HELPER_OBJECTS} ${HELPER_HFILES} \
|
|||
shrpx_ssl.cc shrpx_ssl.h \
|
||||
shrpx_thread_event_receiver.cc shrpx_thread_event_receiver.h \
|
||||
shrpx_worker.cc shrpx_worker.h \
|
||||
shrpx_accesslog.cc shrpx_accesslog.h\
|
||||
http-parser/http_parser.c http-parser/http_parser.h
|
||||
endif # HAVE_LIBEVENT_OPENSSL
|
||||
|
||||
|
|
|
@ -373,6 +373,7 @@ void print_help(std::ostream& out)
|
|||
<< " Specify write timeout for backend\n"
|
||||
<< " connection. Default: "
|
||||
<< get_config()->downstream_write_timeout.tv_sec << "\n"
|
||||
<< " --accesslog Print simple accesslog to stderr.\n"
|
||||
<< " -h, --help Print this help.\n"
|
||||
<< std::endl;
|
||||
}
|
||||
|
@ -405,6 +406,7 @@ int main(int argc, char **argv)
|
|||
{"frontend-write-timeout", required_argument, &flag, 4 },
|
||||
{"backend-read-timeout", required_argument, &flag, 5 },
|
||||
{"backend-write-timeout", required_argument, &flag, 6 },
|
||||
{"accesslog", no_argument, &flag, 7 },
|
||||
{"help", no_argument, 0, 'h' },
|
||||
{0, 0, 0, 0 }
|
||||
};
|
||||
|
@ -492,6 +494,9 @@ int main(int argc, char **argv)
|
|||
mod_config()->downstream_write_timeout = tv;
|
||||
break;
|
||||
}
|
||||
case 7:
|
||||
mod_config()->accesslog = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Spdylay - SPDY Library
|
||||
*
|
||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include "shrpx_accesslog.h"
|
||||
|
||||
#include <ctime>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
namespace shrpx {
|
||||
|
||||
namespace {
|
||||
void get_datestr(char *buf)
|
||||
{
|
||||
time_t now = time(0);
|
||||
if(ctime_r(&now, buf) == 0) {
|
||||
buf[0] = '\0';
|
||||
} else {
|
||||
size_t len = strlen(buf);
|
||||
if(len == 0) {
|
||||
buf[0] = '\0';
|
||||
} else {
|
||||
buf[strlen(buf)-1] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void upstream_connect(const std::string& client_ip)
|
||||
{
|
||||
char datestr[64];
|
||||
get_datestr(datestr);
|
||||
fprintf(stderr, "[%s] %s\n", datestr, client_ip.c_str());
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
void upstream_spdy_stream(const std::string& client_ip, int32_t stream_id)
|
||||
{
|
||||
char datestr[64];
|
||||
get_datestr(datestr);
|
||||
fprintf(stderr, "[%s] %s stream_id=%d\n", datestr, client_ip.c_str(),
|
||||
stream_id);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
} // namespace shrpx
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Spdylay - SPDY Library
|
||||
*
|
||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef SHRPX_ACCESSLOG_H
|
||||
#define SHRPX_ACCESSLOG_H
|
||||
|
||||
#include "shrpx.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace shrpx {
|
||||
|
||||
void upstream_connect(const std::string& client_ip);
|
||||
void upstream_spdy_stream(const std::string& client_ip, int32_t stream_id);
|
||||
|
||||
} // namespace shrpx
|
||||
|
||||
#endif // SHRPX_LOG_H
|
|
@ -31,6 +31,7 @@
|
|||
#include "shrpx_https_upstream.h"
|
||||
#include "shrpx_config.h"
|
||||
#include "shrpx_downstream_connection.h"
|
||||
#include "shrpx_accesslog.h"
|
||||
|
||||
namespace shrpx {
|
||||
|
||||
|
@ -95,6 +96,9 @@ void upstream_eventcb(bufferevent *bev, short events, void *arg)
|
|||
if(ENABLE_LOG) {
|
||||
LOG(INFO) << "Upstream connected. handler " << handler;
|
||||
}
|
||||
if(get_config()->accesslog) {
|
||||
upstream_connect(handler->get_ipaddr());
|
||||
}
|
||||
handler->set_bev_cb(upstream_readcb, upstream_writecb, upstream_eventcb);
|
||||
handler->validate_next_proto();
|
||||
if(ENABLE_LOG) {
|
||||
|
|
|
@ -42,7 +42,8 @@ Config::Config()
|
|||
num_worker(0),
|
||||
spdy_max_concurrent_streams(0),
|
||||
spdy_proxy(false),
|
||||
add_x_forwarded_for(false)
|
||||
add_x_forwarded_for(false),
|
||||
accesslog(false)
|
||||
{}
|
||||
|
||||
namespace {
|
||||
|
|
|
@ -68,6 +68,7 @@ struct Config {
|
|||
size_t spdy_max_concurrent_streams;
|
||||
bool spdy_proxy;
|
||||
bool add_x_forwarded_for;
|
||||
bool accesslog;
|
||||
Config();
|
||||
};
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "shrpx_downstream_connection.h"
|
||||
#include "shrpx_config.h"
|
||||
#include "shrpx_http.h"
|
||||
#include "shrpx_accesslog.h"
|
||||
#include "util.h"
|
||||
|
||||
using namespace spdylay;
|
||||
|
@ -211,6 +212,10 @@ void on_ctrl_recv_callback
|
|||
upstream->rst_stream(downstream, SPDYLAY_INTERNAL_ERROR);
|
||||
return;
|
||||
}
|
||||
if(get_config()->accesslog) {
|
||||
upstream_spdy_stream(upstream->get_client_handler()->get_ipaddr(),
|
||||
frame->syn_stream.stream_id);
|
||||
}
|
||||
downstream->set_request_state(Downstream::HEADER_COMPLETE);
|
||||
if(frame->syn_stream.hd.flags & SPDYLAY_CTRL_FLAG_FIN) {
|
||||
if(ENABLE_LOG) {
|
||||
|
|
Loading…
Reference in New Issue