nghttpx: Add mruby env.server_port to return frontend server side port
This commit is contained in:
parent
d2f4e4e325
commit
09b97a3313
|
@ -267,6 +267,11 @@ respectively.
|
||||||
|
|
||||||
Return IP address of a remote client.
|
Return IP address of a remote client.
|
||||||
|
|
||||||
|
.. rb:attr_reader:: server_port
|
||||||
|
|
||||||
|
Return port number of the server frontend which accepted the
|
||||||
|
connection from client.
|
||||||
|
|
||||||
.. rb:class:: Request
|
.. rb:class:: Request
|
||||||
|
|
||||||
Object to represent request from client. The modification to
|
Object to represent request from client. The modification to
|
||||||
|
|
|
@ -1281,4 +1281,6 @@ StringRef ClientHandler::get_forwarded_for() const {
|
||||||
return StringRef{forwarded_for_};
|
return StringRef{forwarded_for_};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const UpstreamAddr *ClientHandler::get_upstream_addr() const { return faddr_; }
|
||||||
|
|
||||||
} // namespace shrpx
|
} // namespace shrpx
|
||||||
|
|
|
@ -144,6 +144,8 @@ public:
|
||||||
|
|
||||||
Http2Session *select_http2_session(DownstreamAddrGroup &group);
|
Http2Session *select_http2_session(DownstreamAddrGroup &group);
|
||||||
|
|
||||||
|
const UpstreamAddr *get_upstream_addr() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Connection conn_;
|
Connection conn_;
|
||||||
ev_timer reneg_shutdown_timer_;
|
ev_timer reneg_shutdown_timer_;
|
||||||
|
|
|
@ -92,6 +92,18 @@ mrb_value env_get_remote_addr(mrb_state *mrb, mrb_value self) {
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
mrb_value env_get_server_port(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_fixnum_value(faddr->port);
|
||||||
|
}
|
||||||
|
} // 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);
|
||||||
|
@ -103,6 +115,8 @@ 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_port", env_get_server_port,
|
||||||
|
MRB_ARGS_NONE());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mruby
|
} // namespace mruby
|
||||||
|
|
Loading…
Reference in New Issue