Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RewindableInput wrapper to fix issues with middleware that impoli…
…tely eat up non-rewindable input
- Loading branch information
Showing
5 changed files
with
128 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,5 @@ | |
) | ||
end | ||
|
||
use ActionController::RewindableInput | ||
use ActionController::VerbPiggybacking |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module ActionController | ||
class RewindableInput | ||
class RewindableIO < ActiveSupport::BasicObject | ||
def initialize(io) | ||
@io = io | ||
end | ||
|
||
def read(*args) | ||
read_original_io | ||
@io.read(*args) | ||
end | ||
|
||
def rewind | ||
read_original_io | ||
@io.rewind | ||
end | ||
|
||
def method_missing(method, *args, &block) | ||
@io.send(method, *args, &block) | ||
end | ||
|
||
private | ||
def read_original_io | ||
unless @str | ||
@str = @io.read | ||
@io = StringIO.new(@str) | ||
end | ||
end | ||
end | ||
|
||
def initialize(app) | ||
@app = app | ||
end | ||
|
||
def call(env) | ||
env['rack.input'] = RewindableIO.new(env['rack.input']) | ||
@app.call(env) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1adc149
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit seems to cause problems on Passenger due to the fact that RewindableInput doesn’t define respond_to? (due to inheriting from BlankSlate).
respond_to? is called from parse_multipart_with_rewind in rack_ext.rb
1adc149
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I tested with Passenger and it worked fine. Also respond_to? should be delegated to the IO object.
Can you please open a LH ticket and assign it to me.
(This whole patch was intended to fix uploads with Passenger ;)
1adc149
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ll test on a clean rails and make sure its not something stupid I’m doing.
1adc149
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ticket is at http://rails.lighthouseapp.com/projects/8994/tickets/1767-post-requests-broken-on-passenger#ticket-1767-1