Post request with body_stream and parameters

Posted by Damien MATHIEU on Stack Overflow See other posts from Stack Overflow or by Damien MATHIEU
Published on 2010-04-12T12:26:40Z Indexed on 2010/04/12 12:33 UTC
Read the original article Hit count: 329

Filed under:
|
|
|

Hello,

I'm building some kind of proxy.
When I call some url in a rack application, I forward that request to an other url.

The request I forward is a POST with a file and some parameters.
I want to add more parameters.
But the file can be quite big. So I send it with Net::HTTP#body_stream instead of Net::HTTP#body.

I get my request as a Rack::Request object and I create my Net::HTTP object with that.

req = Net::HTTP::Post.new(request.path_info)
req.body_stream = request.body
req.content_type = request.content_type
req.content_length = request.content_length

http = Net::HTTP.new(@host, @port)
res = http.request(req)

I've tried several ways to add the proxy's parameters. But it seems nothing in Net::HTTP allows to add parameters to a body_stream request, only to a body one.

Is there a simpler way to proxy a rack request like that ? Or a clean way to add my parameters to my request ?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about rack