nghttpx: Detect mruby presence and guard mruby related code with ifdef
This commit is contained in:
parent
200217d8ea
commit
d044c58558
30
configure.ac
30
configure.ac
|
@ -119,6 +119,11 @@ AC_ARG_WITH([spdylay],
|
||||||
[Use spdylay [default=check]])],
|
[Use spdylay [default=check]])],
|
||||||
[request_spdylay=$withval], [request_spdylay=check])
|
[request_spdylay=$withval], [request_spdylay=check])
|
||||||
|
|
||||||
|
AC_ARG_WITH([mruby],
|
||||||
|
[AS_HELP_STRING([--with-mruby],
|
||||||
|
[Use mruby [default=check]])],
|
||||||
|
[request_mruby=$withval], [request_mruby=check])
|
||||||
|
|
||||||
AC_ARG_WITH([cython],
|
AC_ARG_WITH([cython],
|
||||||
[AS_HELP_STRING([--with-cython=PATH],
|
[AS_HELP_STRING([--with-cython=PATH],
|
||||||
[Use cython in given PATH])],
|
[Use cython in given PATH])],
|
||||||
|
@ -370,6 +375,30 @@ fi
|
||||||
|
|
||||||
AM_CONDITIONAL([HAVE_SPDYLAY], [ test "x${have_spdylay}" = "xyes" ])
|
AM_CONDITIONAL([HAVE_SPDYLAY], [ test "x${have_spdylay}" = "xyes" ])
|
||||||
|
|
||||||
|
# mruby (for src/nghttpx)
|
||||||
|
LIBS_OLD=$LIBS
|
||||||
|
have_mruby=no
|
||||||
|
if test "x${request_mruby}" != "xno"; then
|
||||||
|
AC_CHECK_LIB([mruby], [mrb_open], [have_mruby=yes], [have_mruby=no])
|
||||||
|
if test "x${have_mruby}" = "xyes"; then
|
||||||
|
AC_CHECK_HEADER([mruby.h], [have_mruby=yes], [have_mruby=no])
|
||||||
|
if test "x${have_mruby}" = "xyes"; then
|
||||||
|
LIBMRUBY_LIBS=-lmruby
|
||||||
|
LIBMRUBY_CFLAGS=
|
||||||
|
AC_SUBST([LIBMRUBY_LIBS])
|
||||||
|
AC_SUBST([LIBMRUBY_CFLAGS])
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
LIBS=$LIBS_OLD
|
||||||
|
|
||||||
|
if test "x${request_mruby}" = "xyes" &&
|
||||||
|
test "x${have_mruby}" != "xyes"; then
|
||||||
|
AC_MSG_ERROR([mruby was requested (--with-mruby) but not found])
|
||||||
|
fi
|
||||||
|
|
||||||
|
AM_CONDITIONAL([HAVE_MRUBY], [test "x${have_mruby}" = "xyes"])
|
||||||
|
|
||||||
# Check Boost Asio library
|
# Check Boost Asio library
|
||||||
have_asio_lib=no
|
have_asio_lib=no
|
||||||
|
|
||||||
|
@ -717,6 +746,7 @@ AC_MSG_NOTICE([summary of build options:
|
||||||
Libev: ${have_libev}
|
Libev: ${have_libev}
|
||||||
Libevent(SSL): ${have_libevent_openssl}
|
Libevent(SSL): ${have_libevent_openssl}
|
||||||
Spdylay: ${have_spdylay}
|
Spdylay: ${have_spdylay}
|
||||||
|
MRuby: ${have_mruby}
|
||||||
Jansson: ${have_jansson}
|
Jansson: ${have_jansson}
|
||||||
Jemalloc: ${have_jemalloc}
|
Jemalloc: ${have_jemalloc}
|
||||||
Zlib: ${have_zlib}
|
Zlib: ${have_zlib}
|
||||||
|
|
|
@ -124,21 +124,26 @@ NGHTTPX_SRCS = \
|
||||||
shrpx_memcached_connection.cc shrpx_memcached_connection.h \
|
shrpx_memcached_connection.cc shrpx_memcached_connection.h \
|
||||||
shrpx_memcached_request.h \
|
shrpx_memcached_request.h \
|
||||||
shrpx_memcached_result.h \
|
shrpx_memcached_result.h \
|
||||||
shrpx_mruby.cc shrpx_mruby.h \
|
|
||||||
shrpx_mruby_module.cc shrpx_mruby_module.h \
|
|
||||||
shrpx_mruby_module_request.cc shrpx_mruby_module_request.h \
|
|
||||||
shrpx_mruby_module_response.cc shrpx_mruby_module_response.h \
|
|
||||||
buffer.h memchunk.h template.h
|
buffer.h memchunk.h template.h
|
||||||
|
|
||||||
if HAVE_SPDYLAY
|
if HAVE_SPDYLAY
|
||||||
NGHTTPX_SRCS += shrpx_spdy_upstream.cc shrpx_spdy_upstream.h
|
NGHTTPX_SRCS += shrpx_spdy_upstream.cc shrpx_spdy_upstream.h
|
||||||
endif # HAVE_SPDYLAY
|
endif # HAVE_SPDYLAY
|
||||||
|
|
||||||
|
if HAVE_MRUBY
|
||||||
|
NGHTTPX_SRCS += \
|
||||||
|
shrpx_mruby.cc shrpx_mruby.h \
|
||||||
|
shrpx_mruby_module.cc shrpx_mruby_module.h \
|
||||||
|
shrpx_mruby_module_request.cc shrpx_mruby_module_request.h \
|
||||||
|
shrpx_mruby_module_response.cc shrpx_mruby_module_response.h
|
||||||
|
endif # HAVE_MRUBY
|
||||||
|
|
||||||
noinst_LIBRARIES = libnghttpx.a
|
noinst_LIBRARIES = libnghttpx.a
|
||||||
libnghttpx_a_SOURCES = ${NGHTTPX_SRCS}
|
libnghttpx_a_SOURCES = ${NGHTTPX_SRCS}
|
||||||
|
|
||||||
nghttpx_SOURCES = shrpx.cc shrpx.h
|
nghttpx_SOURCES = shrpx.cc shrpx.h
|
||||||
nghttpx_LDADD = libnghttpx.a ${LDADD} -lmruby
|
nghttpx_CPPFLAGS = ${AM_CPPFLAGS} @LIBMRUBY_CFLAGS@
|
||||||
|
nghttpx_LDADD = libnghttpx.a ${LDADD} @LIBMRUBY_LIBS@
|
||||||
|
|
||||||
if HAVE_CUNIT
|
if HAVE_CUNIT
|
||||||
check_PROGRAMS += nghttpx-unittest
|
check_PROGRAMS += nghttpx-unittest
|
||||||
|
@ -152,9 +157,10 @@ nghttpx_unittest_SOURCES = shrpx-unittest.cc \
|
||||||
nghttp2_gzip.c nghttp2_gzip.h \
|
nghttp2_gzip.c nghttp2_gzip.h \
|
||||||
buffer_test.cc buffer_test.h \
|
buffer_test.cc buffer_test.h \
|
||||||
memchunk_test.cc memchunk_test.h
|
memchunk_test.cc memchunk_test.h
|
||||||
nghttpx_unittest_CPPFLAGS = ${AM_CPPFLAGS}\
|
nghttpx_unittest_CPPFLAGS = ${AM_CPPFLAGS} @LIBMRUBY_CFLAGS@ \
|
||||||
-DNGHTTP2_TESTS_DIR=\"$(top_srcdir)/tests\"
|
-DNGHTTP2_TESTS_DIR=\"$(top_srcdir)/tests\"
|
||||||
nghttpx_unittest_LDADD = libnghttpx.a ${LDADD} -lmruby @CUNIT_LIBS@ @TESTLDADD@
|
nghttpx_unittest_LDADD = libnghttpx.a ${LDADD} \
|
||||||
|
@LIBMRUBY_LIBS@ @CUNIT_LIBS@ @TESTLDADD@
|
||||||
|
|
||||||
TESTS += nghttpx-unittest
|
TESTS += nghttpx-unittest
|
||||||
endif # HAVE_CUNIT
|
endif # HAVE_CUNIT
|
||||||
|
|
|
@ -160,9 +160,11 @@ int ConnectionHandler::create_single_worker() {
|
||||||
|
|
||||||
single_worker_ = make_unique<Worker>(loop_, sv_ssl_ctx, cl_ssl_ctx, cert_tree,
|
single_worker_ = make_unique<Worker>(loop_, sv_ssl_ctx, cl_ssl_ctx, cert_tree,
|
||||||
ticket_keys_);
|
ticket_keys_);
|
||||||
|
#ifdef HAVE_MRUBY
|
||||||
if (single_worker_->create_mruby_context() != 0) {
|
if (single_worker_->create_mruby_context() != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#endif // HAVE_MRUBY
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -184,9 +186,11 @@ int ConnectionHandler::create_worker_thread(size_t num) {
|
||||||
|
|
||||||
auto worker = make_unique<Worker>(loop, sv_ssl_ctx, cl_ssl_ctx, cert_tree,
|
auto worker = make_unique<Worker>(loop, sv_ssl_ctx, cl_ssl_ctx, cert_tree,
|
||||||
ticket_keys_);
|
ticket_keys_);
|
||||||
|
#ifdef HAVE_MRUBY
|
||||||
if (worker->create_mruby_context() != 0) {
|
if (worker->create_mruby_context() != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#endif // HAVE_MRUBY
|
||||||
|
|
||||||
workers_.push_back(std::move(worker));
|
workers_.push_back(std::move(worker));
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,9 @@
|
||||||
#include "shrpx_http.h"
|
#include "shrpx_http.h"
|
||||||
#include "shrpx_worker.h"
|
#include "shrpx_worker.h"
|
||||||
#include "shrpx_http2_session.h"
|
#include "shrpx_http2_session.h"
|
||||||
|
#ifdef HAVE_MRUBY
|
||||||
#include "shrpx_mruby.h"
|
#include "shrpx_mruby.h"
|
||||||
|
#endif // HAVE_MRUBY
|
||||||
#include "http2.h"
|
#include "http2.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "base64.h"
|
#include "base64.h"
|
||||||
|
@ -318,6 +320,7 @@ int Http2Upstream::on_request_headers(Downstream *downstream,
|
||||||
|
|
||||||
downstream->set_request_state(Downstream::HEADER_COMPLETE);
|
downstream->set_request_state(Downstream::HEADER_COMPLETE);
|
||||||
|
|
||||||
|
#ifdef HAVE_MRUBY
|
||||||
auto upstream = downstream->get_upstream();
|
auto upstream = downstream->get_upstream();
|
||||||
auto handler = upstream->get_client_handler();
|
auto handler = upstream->get_client_handler();
|
||||||
auto worker = handler->get_worker();
|
auto worker = handler->get_worker();
|
||||||
|
@ -329,6 +332,7 @@ int Http2Upstream::on_request_headers(Downstream *downstream,
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif // HAVE_MRUBY
|
||||||
|
|
||||||
if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
||||||
downstream->disable_upstream_rtimer();
|
downstream->disable_upstream_rtimer();
|
||||||
|
@ -1271,6 +1275,7 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream) {
|
||||||
downstream->get_request_http2_scheme());
|
downstream->get_request_http2_scheme());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_MRUBY
|
||||||
if (!downstream->get_non_final_response()) {
|
if (!downstream->get_non_final_response()) {
|
||||||
auto worker = handler_->get_worker();
|
auto worker = handler_->get_worker();
|
||||||
auto mruby_ctx = worker->get_mruby_context();
|
auto mruby_ctx = worker->get_mruby_context();
|
||||||
|
@ -1286,6 +1291,7 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // HAVE_MRUBY
|
||||||
|
|
||||||
size_t nheader = downstream->get_response_headers().size();
|
size_t nheader = downstream->get_response_headers().size();
|
||||||
auto nva = std::vector<nghttp2_nv>();
|
auto nva = std::vector<nghttp2_nv>();
|
||||||
|
|
|
@ -37,7 +37,9 @@
|
||||||
#include "shrpx_log_config.h"
|
#include "shrpx_log_config.h"
|
||||||
#include "shrpx_worker.h"
|
#include "shrpx_worker.h"
|
||||||
#include "shrpx_http2_session.h"
|
#include "shrpx_http2_session.h"
|
||||||
|
#ifdef HAVE_MRUBY
|
||||||
#include "shrpx_mruby.h"
|
#include "shrpx_mruby.h"
|
||||||
|
#endif // HAVE_MRUBY
|
||||||
#include "http2.h"
|
#include "http2.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "template.h"
|
#include "template.h"
|
||||||
|
@ -328,6 +330,7 @@ int htp_hdrs_completecb(http_parser *htp) {
|
||||||
|
|
||||||
downstream->set_request_state(Downstream::HEADER_COMPLETE);
|
downstream->set_request_state(Downstream::HEADER_COMPLETE);
|
||||||
|
|
||||||
|
#ifdef HAVE_MRUBY
|
||||||
auto handler = upstream->get_client_handler();
|
auto handler = upstream->get_client_handler();
|
||||||
auto worker = handler->get_worker();
|
auto worker = handler->get_worker();
|
||||||
auto mruby_ctx = worker->get_mruby_context();
|
auto mruby_ctx = worker->get_mruby_context();
|
||||||
|
@ -336,6 +339,7 @@ int htp_hdrs_completecb(http_parser *htp) {
|
||||||
downstream->set_response_http_status(500);
|
downstream->set_response_http_status(500);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#endif // HAVE_MRUBY
|
||||||
|
|
||||||
// mruby hook may change method value
|
// mruby hook may change method value
|
||||||
|
|
||||||
|
@ -888,6 +892,7 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_MRUBY
|
||||||
if (!downstream->get_non_final_response()) {
|
if (!downstream->get_non_final_response()) {
|
||||||
auto worker = handler_->get_worker();
|
auto worker = handler_->get_worker();
|
||||||
auto mruby_ctx = worker->get_mruby_context();
|
auto mruby_ctx = worker->get_mruby_context();
|
||||||
|
@ -901,6 +906,7 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // HAVE_MRUBY
|
||||||
|
|
||||||
auto connect_method = downstream->get_request_method() == HTTP_CONNECT;
|
auto connect_method = downstream->get_request_method() == HTTP_CONNECT;
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,9 @@
|
||||||
#include "shrpx_downstream_connection.h"
|
#include "shrpx_downstream_connection.h"
|
||||||
#include "shrpx_config.h"
|
#include "shrpx_config.h"
|
||||||
#include "shrpx_http.h"
|
#include "shrpx_http.h"
|
||||||
|
#ifdef HAVE_MRUBY
|
||||||
#include "shrpx_mruby.h"
|
#include "shrpx_mruby.h"
|
||||||
|
#endif // HAVE_MRUBY
|
||||||
#include "shrpx_worker.h"
|
#include "shrpx_worker.h"
|
||||||
#include "shrpx_http2_session.h"
|
#include "shrpx_http2_session.h"
|
||||||
#include "http2.h"
|
#include "http2.h"
|
||||||
|
@ -243,6 +245,7 @@ void on_ctrl_recv_callback(spdylay_session *session, spdylay_frame_type type,
|
||||||
|
|
||||||
downstream->set_request_state(Downstream::HEADER_COMPLETE);
|
downstream->set_request_state(Downstream::HEADER_COMPLETE);
|
||||||
|
|
||||||
|
#ifdef HAVE_MRUBY
|
||||||
auto handler = upstream->get_client_handler();
|
auto handler = upstream->get_client_handler();
|
||||||
auto worker = handler->get_worker();
|
auto worker = handler->get_worker();
|
||||||
auto mruby_ctx = worker->get_mruby_context();
|
auto mruby_ctx = worker->get_mruby_context();
|
||||||
|
@ -254,6 +257,7 @@ void on_ctrl_recv_callback(spdylay_session *session, spdylay_frame_type type,
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif // HAVE_MRUBY
|
||||||
|
|
||||||
if (frame->syn_stream.hd.flags & SPDYLAY_CTRL_FLAG_FIN) {
|
if (frame->syn_stream.hd.flags & SPDYLAY_CTRL_FLAG_FIN) {
|
||||||
if (!downstream->validate_request_bodylen()) {
|
if (!downstream->validate_request_bodylen()) {
|
||||||
|
@ -930,6 +934,7 @@ int SpdyUpstream::on_downstream_header_complete(Downstream *downstream) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_MRUBY
|
||||||
auto worker = handler_->get_worker();
|
auto worker = handler_->get_worker();
|
||||||
auto mruby_ctx = worker->get_mruby_context();
|
auto mruby_ctx = worker->get_mruby_context();
|
||||||
|
|
||||||
|
@ -943,6 +948,7 @@ int SpdyUpstream::on_downstream_header_complete(Downstream *downstream) {
|
||||||
if (downstream->get_response_state() == Downstream::MSG_COMPLETE) {
|
if (downstream->get_response_state() == Downstream::MSG_COMPLETE) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#endif // HAVE_MRUBY
|
||||||
|
|
||||||
if (LOG_ENABLED(INFO)) {
|
if (LOG_ENABLED(INFO)) {
|
||||||
DLOG(INFO, downstream) << "HTTP response header completed";
|
DLOG(INFO, downstream) << "HTTP response header completed";
|
||||||
|
|
|
@ -37,7 +37,9 @@
|
||||||
#include "shrpx_log_config.h"
|
#include "shrpx_log_config.h"
|
||||||
#include "shrpx_connect_blocker.h"
|
#include "shrpx_connect_blocker.h"
|
||||||
#include "shrpx_memcached_dispatcher.h"
|
#include "shrpx_memcached_dispatcher.h"
|
||||||
|
#ifdef HAVE_MRUBY
|
||||||
#include "shrpx_mruby.h"
|
#include "shrpx_mruby.h"
|
||||||
|
#endif // HAVE_MRUBY
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "template.h"
|
#include "template.h"
|
||||||
|
|
||||||
|
@ -266,6 +268,7 @@ MemcachedDispatcher *Worker::get_session_cache_memcached_dispatcher() {
|
||||||
return session_cache_memcached_dispatcher_.get();
|
return session_cache_memcached_dispatcher_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_MRUBY
|
||||||
int Worker::create_mruby_context() {
|
int Worker::create_mruby_context() {
|
||||||
mruby_ctx_ = mruby::create_mruby_context();
|
mruby_ctx_ = mruby::create_mruby_context();
|
||||||
if (!mruby_ctx_) {
|
if (!mruby_ctx_) {
|
||||||
|
@ -278,5 +281,6 @@ int Worker::create_mruby_context() {
|
||||||
mruby::MRubyContext *Worker::get_mruby_context() const {
|
mruby::MRubyContext *Worker::get_mruby_context() const {
|
||||||
return mruby_ctx_.get();
|
return mruby_ctx_.get();
|
||||||
}
|
}
|
||||||
|
#endif // HAVE_MRUBY
|
||||||
|
|
||||||
} // namespace shrpx
|
} // namespace shrpx
|
||||||
|
|
|
@ -51,11 +51,13 @@ class Http2Session;
|
||||||
class ConnectBlocker;
|
class ConnectBlocker;
|
||||||
class MemcachedDispatcher;
|
class MemcachedDispatcher;
|
||||||
|
|
||||||
|
#ifdef HAVE_MRUBY
|
||||||
namespace mruby {
|
namespace mruby {
|
||||||
|
|
||||||
class MRubyContext;
|
class MRubyContext;
|
||||||
|
|
||||||
} // namespace mruby
|
} // namespace mruby
|
||||||
|
#endif // HAVE_MRUBY
|
||||||
|
|
||||||
namespace ssl {
|
namespace ssl {
|
||||||
class CertLookupTree;
|
class CertLookupTree;
|
||||||
|
@ -130,9 +132,11 @@ public:
|
||||||
|
|
||||||
MemcachedDispatcher *get_session_cache_memcached_dispatcher();
|
MemcachedDispatcher *get_session_cache_memcached_dispatcher();
|
||||||
|
|
||||||
|
#ifdef HAVE_MRUBY
|
||||||
int create_mruby_context();
|
int create_mruby_context();
|
||||||
|
|
||||||
mruby::MRubyContext *get_mruby_context() const;
|
mruby::MRubyContext *get_mruby_context() const;
|
||||||
|
#endif // HAVE_MRUBY
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifndef NOTHREADS
|
#ifndef NOTHREADS
|
||||||
|
@ -147,7 +151,9 @@ private:
|
||||||
WorkerStat worker_stat_;
|
WorkerStat worker_stat_;
|
||||||
std::vector<DownstreamGroup> dgrps_;
|
std::vector<DownstreamGroup> dgrps_;
|
||||||
std::unique_ptr<MemcachedDispatcher> session_cache_memcached_dispatcher_;
|
std::unique_ptr<MemcachedDispatcher> session_cache_memcached_dispatcher_;
|
||||||
|
#ifdef HAVE_MRUBY
|
||||||
std::unique_ptr<mruby::MRubyContext> mruby_ctx_;
|
std::unique_ptr<mruby::MRubyContext> mruby_ctx_;
|
||||||
|
#endif // HAVE_MRUBY
|
||||||
struct ev_loop *loop_;
|
struct ev_loop *loop_;
|
||||||
|
|
||||||
// Following fields are shared across threads if
|
// Following fields are shared across threads if
|
||||||
|
|
Loading…
Reference in New Issue