#!/usr/bin/ruby
require 'net/ajp13/server'
require 'erb'
class DumpServer < Net::AJP13::Server
include ERB::Util
TEMPLATE = DATA.read
def process_request(req)
logger.info("Requested from #{req.remote_host}:#{req.remote_addr}")
res = Net::AJP13::Response.new(200)
res['Content-Type'] = 'text/html'
res['Content-Langauge'] = 'en-US'
res.body = ERB.new(TEMPLATE).result(binding)
return res
end
end
serv = DumpServer.new('localhost', 3009)
serv.start
__END__
Ruby/AJP example: Dump Server
User request
Request Line
- Method
- <%=h req.method %>
- Protocol
- <%=h req.protocol %>
- Path
- <%=h req.path%>
HTTP headers
<% req.each do |name, value| %>
- <%=h name %>
- <%=h value %>
<% end %>
Environments
- is_ssl?
- <%= req.is_ssl? %>
- remote_addr
- <%=h req.remote_addr%>
- remote_host
- <%=h req.remote_host%>
- server_name
- <%=h req.server_name%>
- server_port
- <%=h req.server_port%>
AJP attributes
<% req.each_attribute do |name, value| %>
- <%=h name %>
- <%=h value %>
<% end %>
<% if req.body_stream %>
<% body = req.body_stream.read %>
<% if %r(\Atext/) =~ req['content-type'] or
req['content-type'] == 'application/x-www-form-urlencoded' %>
<%=h body %>
<% else %>
<%=[body].pack('m')%>
<% end %>
<% end %>