lib/wunderbar/cgi-methods.rb in wunderbar-0.17.2 vs lib/wunderbar/cgi-methods.rb in wunderbar-0.17.3
- old
+ new
@@ -119,19 +119,37 @@
def self.call(scope)
new.call(scope)
end
def call(scope)
+ # asset support for Rack
+ request = (scope.respond_to? :request) ? scope.request : nil
+ if request and request.path =~ %r{/assets/\w[-.\w]+}
+ path = ('.' + scope.request.path).untaint
+ headers = {'type' => 'text/plain'}
+ headers['type'] = 'application/javascript' if path =~ /\.js$/
+ out?(scope, headers) { File.read path if File.exist? path }
+ return
+ end
+
env = scope.env
accept = env['HTTP_ACCEPT'].to_s
path_info = env['PATH_INFO'].to_s
# implied request types
- xhr_json = Wunderbar::Options::XHR_JSON || (accept =~ /json/)
+ xhr_json = Wunderbar::Options::XHR_JSON || (accept =~ /json/) ||
+ env['HTTP_X_REQUESTED_WITH'].to_s == 'XMLHttpRequest'
text = Wunderbar::Options::TEXT ||
(accept =~ /plain/ and accept !~ /html/)
@xhtml = (accept =~ /xhtml/ or accept == '')
@pdf = (accept =~ /pdf/)
+
+ # parse json arguments
+ if xhr_json and request and request.respond_to? :body
+ if env['CONTENT_TYPE'] =~ %r{^application/json(;.*)?$}
+ scope.params.merge! JSON.parse(scope.request.body.read)
+ end
+ end
# overrides via the command line
xhtml_override = ARGV.include?('--xhtml')
html_override = ARGV.include?('--html')
@pdf ||= ARGV.include?('--pdf')