Permalink
Browse files

fix sub requests

  • Loading branch information...
1 parent e6e76ae commit c72a8aff7015f8600409109e06de9aaa76abcc1d Daniel Mendler committed Dec 9, 2009
Showing with 12 additions and 16 deletions.
  1. +12 −16 lib/rack/embed.rb
View
@@ -5,7 +5,7 @@ module Rack
class Embed
def initialize(app, opts = {})
@app = app
- @max_size = opts[:max_size] || 1024
+ @max_size = opts[:max_size] || 1024000
@mime_types = opts[:mime_types] || %w(text/css application/xhtml+xml text/html)
end
@@ -60,27 +60,23 @@ def html_embed_images(body, env)
def get_image(env, src)
return src if src =~ %r{^\w+://|^data:}
+ path = src.dup
begin
- if src[0..0] != '/'
- path = env['PATH_INFO']
- i = path.rindex('/')
- src = path[0..i] + src
+ if path[0..0] != '/'
+ base = env['PATH_INFO']
+ i = base.rindex('/')
+ path = base[0..i] + path
end
- uri = env['REQUEST_URI'] || env['PATH_INFO']
- i = uri.index('?')
- uri = src + (i ? uri[i..-1] : '')
-
- i = src.index('?')
+ query = ''
+ i = path.index('?')
if i
- path = src[0...i]
- query = env['QUERY_STRING'] || ''
- query += (query.empty? ? '' : '&') + src[i+1..-1]
- else
- path = src
- query = env['QUERY_STRING']
+ query = path[i+1..-1]
+ path = path[0...i]
end
+ uri = query && !query.empty? ? "#{path}?#{query}" : path
+
inclusion_env = env.merge('PATH_INFO' => path,
'REQUEST_PATH' => path,
'REQUEST_URI' => uri,

0 comments on commit c72a8af

Please sign in to comment.