skip main content

Archive for April, 2011

Always adding http_proxy support when using Ruby’s Net:HTTP

posted by Duncan at 8:57 am on April 12th, 2011

Recently there have been a number of times I’ve needed to use Ruby’s Net:HTTP library. Because I develop inside a company firewall, all HTTP traffic has to go through a proxy. This means our libraries always need the Proxy support that Net:HTTP has. This means we now have a common idiom, and here it is:

require 'ostruct'
 
url = URI.parse("http://destination.com")
proxy = ENV['http_proxy'] ? URI.parse(ENV['http_proxy']) : OpenStruct.new
 
conn = Net::HTTP::Proxy(proxy.host, proxy.port).new(url.host, url.port)

Simple! You can use this every time, and your lib will have proxy support based on the http_proxy environment variable being set. If it’s not set, then it will just carry on as expected.

Fixing the 400 Bad Request problem with Solr 3.1.0 and Ruby-Solr

posted by Duncan at 6:44 pm on April 5th, 2011

After seeing a tweet by Matt Biddulph the other day, mentioning that a Solr had a new 3.1 release, I thought I’d take a look. I decided to replace the 1.4 version we have at work, even though we are currently scratching the surface of what Solr can bring to a project.

Anyway, the install seem to go smoothly, and the admin screen was up and navigable. I went to one the application we have running against it though, and saw nothing but “Bad Request 400″ errors. Strange. Initially I thought the problem was down to the ruby-solr gem I was using, but with further investicgation it proved to be a Solr problem. Going to the admin area, and in the “Make a Query” section clicking “full interface“, I would make a query and get the same error! If I removed ‘standard’ from the query type things worked ok.

Checking the solrconfig.xml config file and you will see there is a line:

<requestHandler name="search" class="solr.SearchHandler">

I changed this to

<requestHandler name="standard" class="solr.SearchHandler">

and everything was fixed for me. It looks like someone changed the Handler name? anyway it was expecting a requestHandler with a name standard by default. This is also why ruby-solr was bailing.

Now I’m no Solr expert here, so if anyone has a clearer explanation I love to here it. Further searching has since found this is a bug which appears to have been fixed, but you’ll have to wait for the next release to see it.


back to the top