Class: N::App::WebrickServlet

Inherits:
WEBrick::HTTPServlet::AbstractServlet
  • Object
show all
Includes:
WEBrick
Defined in:
lib/n/app/webrick-servlet.rb

Overview

WebrickServlet

Instance Method Summary collapse

Instance Method Details

#do_GET(wreq, wres) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/n/app/webrick-servlet.rb', line 59

def do_GET(wreq, wres)
	request = create_request(wreq)
	request.session = create_session(request)

	extension = N::StringUtils.extension_from_path(request.path)
	handler = $srv_extension_map[extension][1]

	begin
		fragment, script = handler.process(request)

		if fragment
			request.out["Content-Type"] = "text/html" unless request.out["Content-Type"]		
			request.out_buffer = fragment.body
		end
		
		unless request.expires?
			request.expires!(Time.now())
		end
		
	rescue Exception, StandardError => e
		$log.error "error while handling the request #{request.uri}"
		$log.error pp_exception(e)

		if $error_page_url
			# internal redirect to error page. 
			# gmosx: reset handler for .rx pages.
			handler = $srv_extension_map["sx"][1]
			request.path = $error_page_url
			retry
		else
			# no custom error page defined. Presen a simple yet 
			# useful error screen.
			request.out["Content-Type"] = "text/html"
			body = %{
				<h1>ERROR</h1>
				<p>Click <a href="#{request.referer}">here</a> to return 
				to the previous page.</p>
			}
			if request.error_log
				body << %{
					<h3>Request error log</h3>
					<pre>#{request.error_log.join("\n")}</pre>
				}
			end
			body << %{
				<h3>Exception</h3>
				<pre>#{pp_exception(e)}</pre>
			}
			request.out_buffer = body
		end
	end
	
	# gmosx: optimize me, do something more clever!!!
	request.session.synchronize!

	wres.status = request.status
	wres.header = request.out
	wres.cookies = request.out_cookies.values()
	wres.body = request.out_buffer
end

#do_POST(wreq, wres) ⇒ Object



120
121
122
# File 'lib/n/app/webrick-servlet.rb', line 120

def do_POST(wreq, wres)
	do_GET(wreq, wres)
end