Martin Sarsale
2008-Aug-05 17:45 UTC
[Mechanize-users] "boundaries" not set when reposting a form with authentication
When mechanize posts a form to a resource needing authentication, the first request is done without sending the credentials. When the server answers a 401, the uri.host is added to @auth_hash and the fetch_page method is called again. This way, when the request is being prepared it includes the credentials. The problem is that in this 2nd request, the "boundary" "attribute" in the content-type header is not set, because when the request is recreated (using fetch_request) for passing fetch_page it doesn''t includes the ''special'' headers. More specifically: return fetch_page( uri, fetch_request(uri, request.method.downcase.to_sym), cur_page, request_data ) Trying to reuse the original request ("request") fails because the @body instance attr is already set; but if it''s cleared before it can be reused: request.body = nil return fetch_page( uri, request, cur_page, request_data ) This fixes my problem (it''s just a test script), but I''m not sure if it breaks something else. So please take this as a bug report and not a patch :) thanks -- Martin Sarsale - martin at malditainternet.com
Aaron Patterson
2008-Aug-05 17:56 UTC
[Mechanize-users] "boundaries" not set when reposting a form with authentication
On Tue, Aug 5, 2008 at 10:45 AM, Martin Sarsale <martin at malditainternet.com> wrote:> When mechanize posts a form to a resource needing authentication, the > first request is done without sending the credentials. When the server > answers a 401, the uri.host is added to @auth_hash and the fetch_page > method is called again. This way, when the request is being prepared > it includes the credentials. > > The problem is that in this 2nd request, the "boundary" "attribute" in > the content-type header is not set, because when the request is > recreated (using fetch_request) for passing fetch_page it doesn''t > includes the ''special'' headers. > > More specifically: > > return fetch_page( uri, > > fetch_request(uri, request.method.downcase.to_sym), > > cur_page, > > request_data > > ) > > > > Trying to reuse the original request ("request") fails because the > @body instance attr is already set; but if it''s cleared before it can > be reused: > > request.body = nil > return fetch_page( uri, > request, > cur_page, > request_data > ) > > This fixes my problem (it''s just a test script), but I''m not sure if > it breaks something else. So please take this as a bug report and not > a patch :)Thanks Martin, I''ll look in to this. -- Aaron Patterson http://tenderlovemaking.com/