Commit 99f7e7e2 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

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

parent 6c999e6f
......@@ -265,13 +265,25 @@ respectively.
.. 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
Return port number of the server frontend which accepted the
connection from client.
.. rb:attr_reader:: tls_used
Return true if TLS is used on the connection.
.. rb:class:: Request
Object to represent request from client. The modification to
......
......@@ -104,6 +104,29 @@ mrb_value env_get_server_port(mrb_state *mrb, mrb_value self) {
}
} // 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) {
auto env_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, "remote_addr", env_get_remote_addr,
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_ARGS_NONE());
mrb_define_method(mrb, env_class, "tls_used", env_get_tls_used,
MRB_ARGS_NONE());
}
} // namespace mruby
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment