[twitter-dev] Re: Anyone updated jmathai OAuth library for 301s?
I didn't know FOLLOWLOCATION didn't work for posts :). Looks like the only way to fix it is to manually follow the url in the header for 301/302s. http://github.com/jmathai/twitter-async/issues/#issue/20 On Aug 31, 8:44 am, davidddn david.dellan...@gmail.com wrote: Has anyone updated the Jaisen Mathai OAuth library to support manually following the 301s? Since FOLLOW_LOCATION doesn't work on POSTs, the library needs to be re-written in parts to manually follow the redirects. Don't want to duplicate the work if someone has done it. The code is here:https://github.com/jmathai/twitter-async/tree
[twitter-dev] Re: Anyone updated jmathai OAuth library for 301s?
I'm reconsidering adding support for POSTs. What's the usecase exactly? Does Twitter 302 POST requests? If so, what's gained by the application if it follows that? On Aug 31, 8:44 am, davidddn david.dellan...@gmail.com wrote: Has anyone updated the Jaisen Mathai OAuth library to support manually following the 301s? Since FOLLOW_LOCATION doesn't work on POSTs, the library needs to be re-written in parts to manually follow the redirects. Don't want to duplicate the work if someone has done it. The code is here:https://github.com/jmathai/twitter-async/tree
[twitter-dev] Re: Anyone updated jmathai OAuth library for 301s?
On Sep 1, 5:00 pm, jmathai jmat...@gmail.com wrote: I'm reconsidering adding support for POSTs. What's the usecase exactly? Does Twitter 302 POST requests? If so, what's gained by the application if it follows that? Unless I am mistaken Twitter is still doing the 302 on POST as a countermeasure for their DDoS problem. It's not that anything is gained, it's that the library doesn't work without it.
[twitter-dev] Re: Anyone updated jmathai OAuth library for 301s?
On Sep 1, 6:41 pm, jmathai jmat...@gmail.com wrote: That's a valid point. What do you think of following on GETs and throwing an exception for POSTs? Not sure many people like to deal with exceptions (I prefer them). It would be helpful if someone from Twitter or who has done some extensive testing of the 302 behavior could chime in. IF re-trying the request after NOT following a 302 on a POST doesn't bypass the DDoS countermeasure than throwing an exception is completely useless. IF re-trying the request after encountering a 302 DOES work, than throwing an exception would be sufficient to solve the problem. Personally I'd rather just see the library follow the 301/302 on POST and GET, but I can see where throwing an exception would be the more compliant approach. Can someone chime in on this please?
[twitter-dev] Re: Anyone updated jmathai OAuth library for 301s?
I've just coded this function which may help : function redirect_post($url,$data) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); list($header,$content) = preg_split(#(\r)?\n(\r)?\n#s,curl_exec ($ch),2); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if (in_array($http_code,array(301,302))) { $redir = preg_match(#Location:(.*?)\n#si,$header,$m) ? trim($m [1]) : ''; if ($redir ($redir != $url)) return redirect_post($redir,$data); } return $content; } I've tested, it's ok ; and shouldn't be so hard to use in the lib. I'll have to use the Jaisen Mathai OAuth library very soon too, so if no solution has been found I'll post mine here :) FB
[twitter-dev] Re: Anyone updated jmathai OAuth library for 301s?
One the issues is that the twitter-sync library utilizes multicurl which allows for parallel requests. Introducing this type of logic is tricky since the library allows you to access the results later and only at that point can we inspect the headers. Most people probably use it in a manner where they immediately block for the results, but I don't think sacrificing the ability to do parallel requests is worth following 302s. Anyways, I'd like to know from Twitter what their plans are for the 302 redirects. Is it temporary? It's far from an ideal solution and seems more like a stop gap. However, I don't think they'll chime in on this thread due to the title. Perhaps a new general thread would be appropriate. Jaisen On Sep 1, 7:06 pm, fbparis fbou...@gmail.com wrote: I've just coded this function which may help : function redirect_post($url,$data) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); list($header,$content) = preg_split(#(\r)?\n(\r)?\n#s,curl_exec ($ch),2); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if (in_array($http_code,array(301,302))) { $redir = preg_match(#Location:(.*?)\n#si,$header,$m) ? trim($m [1]) : ''; if ($redir ($redir != $url)) return redirect_post($redir,$data); } return $content; } I've tested, it's ok ; and shouldn't be so hard to use in the lib. I'll have to use the Jaisen Mathai OAuth library very soon too, so if no solution has been found I'll post mine here :) FB