From hding2 at illinois.edu Thu Dec 6 17:26:51 2012 From: hding2 at illinois.edu (Ding, Howard Adrian) Date: Thu, 6 Dec 2012 17:26:51 +0000 Subject: [Mechanize-users] redirect with DELETE question Message-ID: <908C93BC07BF2E43B25345AFA2950E8D4CAFE577@CHIMBX6.ad.uillinois.edu> Hi, I'm a fairly new user of mechanize and for the most part it's working out well for me. I do have a question though. We have a system where when sometimes when sending a delete request the system will send a redirect and we then need to delete as specified by the redirect. However, doing this naively with Mechanize results in the initial delete being sent correctly, the redirect being received, and then a second request being issued but as a GET instead of a DELETE. Is there any automatic way to get mechanize to reissue a DELETE to the redirect location, or do I have to do things more manually (e.g. don't follow redirects, read the code manually, and reissue manually if I get a redirect)? Thanks, Howard Howard Ding Visiting Research Programmer 135 Grainger Engineering Library 217-300-1763 / hding2 at illinois.edu -------------- next part -------------- An HTML attachment was scrubbed... URL: From drbrain at segment7.net Thu Dec 6 19:37:50 2012 From: drbrain at segment7.net (Eric Hodel) Date: Thu, 6 Dec 2012 11:37:50 -0800 Subject: [Mechanize-users] redirect with DELETE question In-Reply-To: <908C93BC07BF2E43B25345AFA2950E8D4CAFE577@CHIMBX6.ad.uillinois.edu> References: <908C93BC07BF2E43B25345AFA2950E8D4CAFE577@CHIMBX6.ad.uillinois.edu> Message-ID: <72E98FA7-4306-4E92-A008-DC9A5B819610@segment7.net> On Dec 6, 2012, at 9:26, "Ding, Howard Adrian" wrote: > Is there any automatic way to get mechanize to reissue a DELETE to the redirect location, or do I have to do things more manually (e.g. don't follow redirects, read the code manually, and reissue manually if I get a redirect)? > According to RFC 2616 section 10.3 only GET and HEAD requests may follow redirects. So there is a bug here in mechanize, it should not make a GET request to the Location returned, but we cannot automatically reissue the DELETE. (At least the extra GET will be harmless for HTTP-compliant applications.) Can you create an issue on https://github.com/sparklemotion/mechanize? If we return some kind of redirect pending response for you DELETE redirect it will make it easier to implement your application-specific behavior, at least. -------------- next part -------------- An HTML attachment was scrubbed... URL: From hding2 at illinois.edu Thu Dec 6 19:41:45 2012 From: hding2 at illinois.edu (Ding, Howard Adrian) Date: Thu, 6 Dec 2012 19:41:45 +0000 Subject: [Mechanize-users] redirect with DELETE question In-Reply-To: <72E98FA7-4306-4E92-A008-DC9A5B819610@segment7.net> References: <908C93BC07BF2E43B25345AFA2950E8D4CAFE577@CHIMBX6.ad.uillinois.edu> <72E98FA7-4306-4E92-A008-DC9A5B819610@segment7.net> Message-ID: <908C93BC07BF2E43B25345AFA2950E8D4CAFE621@CHIMBX6.ad.uillinois.edu> It may well be that the particular product we're using this with is not conforming with the spec, but that's what we have. I'll find some time to put an issue in, but I may also fork (at least temporarily) and make it work as we need for our purposes. Thanks, Howard Howard Ding Visiting Research Programmer 135 Grainger Engineering Library 217-300-1763 / hding2 at illinois.edu From: mechanize-users-bounces at rubyforge.org [mailto:mechanize-users-bounces at rubyforge.org] On Behalf Of Eric Hodel Sent: Thursday, December 06, 2012 1:38 PM To: Ruby Mechanize Users List Subject: Re: [Mechanize-users] redirect with DELETE question On Dec 6, 2012, at 9:26, "Ding, Howard Adrian" > wrote: Is there any automatic way to get mechanize to reissue a DELETE to the redirect location, or do I have to do things more manually (e.g. don't follow redirects, read the code manually, and reissue manually if I get a redirect)? According to RFC 2616 section 10.3 only GET and HEAD requests may follow redirects. So there is a bug here in mechanize, it should not make a GET request to the Location returned, but we cannot automatically reissue the DELETE. (At least the extra GET will be harmless for HTTP-compliant applications.) Can you create an issue on https://github.com/sparklemotion/mechanize? If we return some kind of redirect pending response for you DELETE redirect it will make it easier to implement your application-specific behavior, at least. -------------- next part -------------- An HTML attachment was scrubbed... URL: From snowhitster at gmail.com Thu Dec 6 19:48:06 2012 From: snowhitster at gmail.com (Timothy Snowhite) Date: Thu, 6 Dec 2012 14:48:06 -0500 Subject: [Mechanize-users] redirect with DELETE question In-Reply-To: <72E98FA7-4306-4E92-A008-DC9A5B819610@segment7.net> References: <908C93BC07BF2E43B25345AFA2950E8D4CAFE577@CHIMBX6.ad.uillinois.edu> <72E98FA7-4306-4E92-A008-DC9A5B819610@segment7.net> Message-ID: Howard, This is the section of the code you would need to modify: https://github.com/sparklemotion/mechanize/blob/master/lib/mechanize/http/agent.rb#L926-L953 I like Eric's suggestion of having some form of "redirect confirmation" callback or return value, however. " If the 301 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued. Note: When automatically redirecting a POST request after receiving a 301 status code, some existing HTTP/1.0 user agents will erroneously change it into a GET request. " - http://www.ietf.org/rfc/rfc2616.txt Since mechanize is acting as both user-agent and deciding user in this case, I think it makes sense to provide some scriptability of this behavior. -Tim On Thu, Dec 6, 2012 at 2:37 PM, Eric Hodel wrote: > On Dec 6, 2012, at 9:26, "Ding, Howard Adrian" > wrote: > > Is there any automatic way to get mechanize to reissue a DELETE to the > redirect location, or do I have to do things more manually (e.g. don't > follow redirects, read the code manually, and reissue manually if I get a > redirect)? > > According to RFC 2616 section 10.3 only GET and HEAD requests may follow > redirects. > > So there is a bug here in mechanize, it should not make a GET request to > the Location returned, but we cannot automatically reissue the DELETE. (At > least the extra GET will be harmless for HTTP-compliant applications.) > > Can you create an issue on https://github.com/sparklemotion/mechanize? If > we return some kind of redirect pending response for you DELETE redirect it > will make it easier to implement your application-specific behavior, at > least. > > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From drbrain at segment7.net Thu Dec 6 20:14:05 2012 From: drbrain at segment7.net (Eric Hodel) Date: Thu, 6 Dec 2012 12:14:05 -0800 Subject: [Mechanize-users] redirect with DELETE question In-Reply-To: <908C93BC07BF2E43B25345AFA2950E8D4CAFE621@CHIMBX6.ad.uillinois.edu> References: <908C93BC07BF2E43B25345AFA2950E8D4CAFE577@CHIMBX6.ad.uillinois.edu> <72E98FA7-4306-4E92-A008-DC9A5B819610@segment7.net> <908C93BC07BF2E43B25345AFA2950E8D4CAFE621@CHIMBX6.ad.uillinois.edu> Message-ID: <00C3953E-487B-46FE-919F-60DDA6AC5DC3@segment7.net> On Dec 6, 2012, at 11:41, "Ding, Howard Adrian" wrote: > It may well be that the particular product we're using this with is not conforming with the spec, but that's what we have. Your server is spec-compliant, but there are restrictions on what mechanize may do. It's fine for the server to return a redirect for a DELETE request, but it's not fine for a general-purpose user-agent like mechanize to automatically send a DELETE to the redirect location. If you build something atop mechanize that has application-specific knowledge, it's fine for that program to automatically DELETE the redirect location. From hding2 at illinois.edu Thu Dec 6 20:17:07 2012 From: hding2 at illinois.edu (Ding, Howard Adrian) Date: Thu, 6 Dec 2012 20:17:07 +0000 Subject: [Mechanize-users] redirect with DELETE question In-Reply-To: <00C3953E-487B-46FE-919F-60DDA6AC5DC3@segment7.net> References: <908C93BC07BF2E43B25345AFA2950E8D4CAFE577@CHIMBX6.ad.uillinois.edu> <72E98FA7-4306-4E92-A008-DC9A5B819610@segment7.net> <908C93BC07BF2E43B25345AFA2950E8D4CAFE621@CHIMBX6.ad.uillinois.edu> <00C3953E-487B-46FE-919F-60DDA6AC5DC3@segment7.net> Message-ID: <908C93BC07BF2E43B25345AFA2950E8D4CAFE650@CHIMBX6.ad.uillinois.edu> That's fine. I'm reporting the issue now and if Mechanize can provide a compliant way to deal with this in the future I'll be fine, and for my purposes now I'll just fork it and make it an agent specific to our application here. :-) Thanks, Howard Howard Ding Visiting Research Programmer 135 Grainger Engineering Library 217-300-1763 / hding2 at illinois.edu -----Original Message----- From: mechanize-users-bounces at rubyforge.org [mailto:mechanize-users-bounces at rubyforge.org] On Behalf Of Eric Hodel Sent: Thursday, December 06, 2012 2:14 PM To: Ruby Mechanize Users List Subject: Re: [Mechanize-users] redirect with DELETE question On Dec 6, 2012, at 11:41, "Ding, Howard Adrian" wrote: > It may well be that the particular product we're using this with is not conforming with the spec, but that's what we have. Your server is spec-compliant, but there are restrictions on what mechanize may do. It's fine for the server to return a redirect for a DELETE request, but it's not fine for a general-purpose user-agent like mechanize to automatically send a DELETE to the redirect location. If you build something atop mechanize that has application-specific knowledge, it's fine for that program to automatically DELETE the redirect location. _______________________________________________ Mechanize-users mailing list Mechanize-users at rubyforge.org http://rubyforge.org/mailman/listinfo/mechanize-users From hding2 at illinois.edu Thu Dec 13 19:17:29 2012 From: hding2 at illinois.edu (Ding, Howard Adrian) Date: Thu, 13 Dec 2012 19:17:29 +0000 Subject: [Mechanize-users] posting large files Message-ID: <908C93BC07BF2E43B25345AFA2950E8D4CAFF327@CHIMBX6.ad.uillinois.edu> Hi, I'm curious if there are any recommended ways to post large files (directly, not through a form) with Mechanize. E.g. I have something like the following: content = File.open(file_path, 'rb') { |f| f.read } self.client.post(file_url(bit_file), content, ingest_headers(bit_file, file_path, opts[:path])) but this requires reading the entire content of the file into memory to make the post. I see that on the GET side there is a method called download which appears to function like a GET but to write the response body directly to a file without having to have it all in memory at once, and I guess I'm looking to see if there is anything similar for posting, as I may come up against situations where I need to post files that are significantly larger than my machines memory. Thanks, Howard Howard Ding Visiting Research Programmer 135 Grainger Engineering Library 217-300-1763 / hding2 at illinois.edu -------------- next part -------------- An HTML attachment was scrubbed... URL: From juanjose at jesco.com.mx Wed Dec 19 19:58:00 2012 From: juanjose at jesco.com.mx (Juan Jose Lopez Gonzalez) Date: Wed, 19 Dec 2012 13:58:00 -0600 Subject: [Mechanize-users] (no subject) Message-ID: <50D21C48.3070506@jesco.com.mx> hello, I have a problem, I want to do is get a certificate .p12, I am implementing the following code: m= Mechanize.new m.log = Logger.new "m.log" m.user_agent_alias = "Mac Safari" if RbConfig::CONFIG["host_os"] =~ /mingw|mswin/ ca_path = File.expand_path "C:/Users/amdx3/Desktop/cacert.p12" m.agent.http.ca_file = ca_path end pag = m.get "https://www.newpage.com.mx/login" # the site is only informative form = pagina.forms.first campos = form.fields.find_all titulo = pagina.title form.field_with(:name => "username").value = "******" only informative form.field_with(:name => "password").value = "******" only informative search_results = m.submit form @page = search_results.body and display this: Action Controller: Exception caught OpenSSL::SSL::SSLError in AutoController#login SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed I?m new at this, help! -- --------------------------------------------------- *Juan Jos? L?pez Gonz?lez* Jesco Solutions S.A. de C.V. Tel. / fax (33) 3122-1313 --------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: juanjose.vcf Type: text/x-vcard Size: 268 bytes Desc: not available URL: