nghttpx: Add mruby env.server_addr and env.tls_used attributes

This commit is contained in:
Tatsuhiro Tsujikawa 2016-04-29 12:17:25 +09:00
parent 6c999e6fb5
commit 99f7e7e2a5
2 changed files with 40 additions and 1 deletions

View File

@ -265,13 +265,25 @@ respectively.
.. rb:attr_reader:: remote_addr .. rb:attr_reader:: remote_addr
Return IP address of a remote client. Return IP address of a remote client. If connection is made
via UNIX domain socket, this returns the string "localhost".
.. rb:attr_reader:: server_addr
Return address of server that accepted the connection. This
is a string which specified in :option:`--frontend` option,
excluding port number, and not a resolved IP address. For
UNIX domain socket, this is a path to UNIX domain socket.
.. rb:attr_reader:: server_port .. rb:attr_reader:: server_port
Return port number of the server frontend which accepted the Return port number of the server frontend which accepted the
connection from client. connection from client.
.. rb:attr_reader:: tls_used
Return true if TLS is used on the connection.
.. rb:class:: Request .. rb:class:: Request
Object to represent request from client. The modification to Object to represent request from client. The modification to

View File

@ -104,6 +104,29 @@ mrb_value env_get_server_port(mrb_state *mrb, mrb_value self) {
} }
} // namespace } // namespace
namespace {
mrb_value env_get_server_addr(mrb_state *mrb, mrb_value self) {
auto data = static_cast<MRubyAssocData *>(mrb->ud);
auto downstream = data->downstream;
auto upstream = downstream->get_upstream();
auto handler = upstream->get_client_handler();
auto faddr = handler->get_upstream_addr();
return mrb_str_new(mrb, faddr->host.c_str(), faddr->host.size());
}
} // namespace
namespace {
mrb_value env_get_tls_used(mrb_state *mrb, mrb_value self) {
auto data = static_cast<MRubyAssocData *>(mrb->ud);
auto downstream = data->downstream;
auto upstream = downstream->get_upstream();
auto handler = upstream->get_client_handler();
return handler->get_ssl() ? mrb_true_value() : mrb_false_value();
}
} // namespace
void init_env_class(mrb_state *mrb, RClass *module) { void init_env_class(mrb_state *mrb, RClass *module) {
auto env_class = auto env_class =
mrb_define_class_under(mrb, module, "Env", mrb->object_class); mrb_define_class_under(mrb, module, "Env", mrb->object_class);
@ -115,8 +138,12 @@ void init_env_class(mrb_state *mrb, RClass *module) {
mrb_define_method(mrb, env_class, "phase", env_get_phase, MRB_ARGS_NONE()); mrb_define_method(mrb, env_class, "phase", env_get_phase, MRB_ARGS_NONE());
mrb_define_method(mrb, env_class, "remote_addr", env_get_remote_addr, mrb_define_method(mrb, env_class, "remote_addr", env_get_remote_addr,
MRB_ARGS_NONE()); MRB_ARGS_NONE());
mrb_define_method(mrb, env_class, "server_addr", env_get_server_addr,
MRB_ARGS_NONE());
mrb_define_method(mrb, env_class, "server_port", env_get_server_port, mrb_define_method(mrb, env_class, "server_port", env_get_server_port,
MRB_ARGS_NONE()); MRB_ARGS_NONE());
mrb_define_method(mrb, env_class, "tls_used", env_get_tls_used,
MRB_ARGS_NONE());
} }
} // namespace mruby } // namespace mruby