Skip to main content

Posts

Showing posts from January, 2009

Ruby net/http+SSL+Basic Auth

Since one post from this blog is (or at least used to be) a little chunk of official documentation for Basic Auth in Ruby, I decided I should write this down also. Socialtext is switching some of the SaaS servers to be https all the time. So I had to rejigger my selenium test-runner script, because it reads (test data) from and writes (test results) to the wiki. I found this very elegant example . My take on it looks like def put_test_results_to_wiki http = Net::HTTP.new(@test_host,443) req = Net::HTTP::Put.new(@put_loc, initheader = {'Content-Type' =>'text/x.socialtext-wiki'}) http.use_ssl = true req.basic_auth @test_user, @test_pass req.body = ".pre\n" + @content + "\n.pre" response = http.request(req) puts response end What is a little peculiar about this is that Basic Auth is very much optional for SSL connections. Normally the client would do a GET, the ser...