Module: Raw::AdapterHandlerMixin

Included in:
MongrelHandler, ScriptAdapter, WebrickHandler
Defined in:
lib/raw/adapter.rb

Overview

This mixin provides default functionality to adapter handlers.

Instance Method Summary collapse

Instance Method Details

#handle_context(context) ⇒ Object

Handle a context. Returns the generated output.



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
# File 'lib/raw/adapter.rb', line 59

def handle_context(context)
  Cgi.parse_params(context)
  Cgi.parse_cookies(context)    
  
  controller, action, query, params, ext = @application.dispatcher.dispatch_context(context)
  context.content_type = context.format.content_type
  
  Thread.current[:CURRENT_CONTROLLER] = controller
  controller = controller.new(context)

  controller.send(action, params)
  # res.chunked = true if controller.out.is_a?(IO) and context["SERVER_PROTOCOL"] == "HTTP/1.1"    
rescue RenderExit, ActionExit => e1
  # Just stop rendering.     
  
rescue ActionError => e2
  # Client Error family of errors, typically send 4XX
  # status code.
  debug e2.to_s if $DBG
      
rescue Object => e3
  # Server Error family of errors, typically send 5XX
  # status code.
  error "Error while handling '#{context.uri}'"
  error pp_exception(e3)
  
ensure
  Og.manager.put_store if defined?(Og) and Og.respond_to?(:manager) and Og.manager
  return context.output_buffer
end

#rewrite(req) ⇒ Object

Try to rewrite the path to a filename.



92
93
94
95
96
97
98
# File 'lib/raw/adapter.rb', line 92

def rewrite(req)
  if req.path_info == "/"
    req.path_info = "/index.html" 
  elsif req.path_info =~ /^([^.]+)$/
    req.path_info = "#{$1}.html" 
  end
end

#unrewrite(req) ⇒ Object

Rewrite back to the original path.



102
103
104
105
106
107
108
# File 'lib/raw/adapter.rb', line 102

def unrewrite(req)
  if req.path_info == "/index.html"
    req.path_info = "/" 
  elsif req.path_info =~ /^([^.]+)\.html$/    
    req.path_info = $1 
  end
end