lib/merb/mixins/controller_mixin.rb in merb-0.3.1 vs lib/merb/mixins/controller_mixin.rb in merb-0.3.3
- old
+ new
@@ -16,51 +16,58 @@
bufsize = 16384
content_length -= boundary_size
status = input.read(boundary_size)
raise EOFError, "bad content body" unless status == boundary + EOL
rx = /(?:#{EOL})?#{Regexp.quote(boundary,'n')}(#{EOL}|--)/
-
loop {
head = nil
body = ''
filename = content_type = name = nil
-
+ read_size = 0
until head && buf =~ rx
- if !head && i = buf.index("\r\n\r\n")
+ i = buf.index("\r\n\r\n")
+ if( i == nil && read_size == 0 && content_length == 0 )
+ content_length = -1
+ break
+ end
+ if !head && i
head = buf.slice!(0, i+2) # First \r\n
buf.slice!(0, 2) # Second \r\n
-
filename = head[FILENAME_REGEX, 1]
content_type = head[CONTENT_TYPE_REGEX, 1]
name = head[NAME_REGEX, 1]
- if filename && !filename.empty?
+ if filename && !filename.empty?
body = Tempfile.new(:Merb)
body.binmode if defined? body.binmode
end
next
end
-
+
+
# Save the read body part.
if head && (boundary_size+4 < buf.size)
body << buf.slice!(0, buf.size - (boundary_size+4))
end
- c = input.read(bufsize < content_length ? bufsize : content_length)
- raise EOFError, "bad content body" if c.nil? || c.empty?
- buf << c
- content_length -= c.size
+ read_size = bufsize < content_length ? bufsize : content_length
+ if( read_size > 0 )
+ c = input.read(read_size)
+ raise EOFError, "bad content body" if c.nil? || c.empty?
+ buf << c
+ content_length -= c.size
+ end
end
-
+
# Save the rest.
if i = buf.index(rx)
body << buf.slice!(0, i)
buf.slice!(0, boundary_size+2)
content_length = -1 if $1 == "--"
end
-
+
if filename && !filename.empty?
body.rewind
data = {
:filename => File.basename(filename),
:content_type => content_type,
@@ -90,10 +97,14 @@
parms[key] = val if val
end
parms
end
+ def url(path, o={})
+ ::Merb::Router.generator.generate(path,o)
+ end
+
# parses a query string or the payload of a POST
# request into the params hash. So for example:
# /foo?bar=nik&post[title]=heya&post[body]=whatever
# parses into:
# {:bar => 'nik', :post => {:title => 'heya', :body => 'whatever'}}
@@ -244,6 +255,6 @@
def unescape(s)
Mongrel::HttpRequest.unescape(s)
end
end
-end
\ No newline at end of file
+end