<?xml version="1.0" encoding="UTF-8"?>
<wiki>
  <body>&lt;p&gt;If Solr application has basic http authentication then the need to have the following code which pass http authentication headers&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
# chauhansudhir@gmail.com
# override solr class to set http authentication
require 'solr'
class Solr::Connection
  # send the http post request to solr; for convenience there are shortcuts
  # to some requests: add(), query(), commit(), delete() or send()
  def post(request)

    # in gem user name and password can be initialized in constructor  
    @user = @password = nil
    @user = URI.decode(@url.user) if @url.user
    @password = URI.decode(@url.password) if @url.password

    
    response = @connection.post(@url.path + &quot;/&quot; + request.handler,
                                request.to_s, build_headers({&quot;Content-Type&quot; =&amp;gt; request.content_type})
                                )
    case response
    when Net::HTTPSuccess then response.body
    else
      response.error!
    end  
  end
  
  # build headers
  def build_headers(header)
    authorization_header.update(header)
  end
  
  # generate http basic authentication header
  def authorization_header
    (@user || @password ? { 'Authorization' =&amp;gt; 'Basic ' + [&quot;#{@user}:#{ @password}&quot;].pack('m').delete(&quot;\r\n&quot;) } : {})
  end
end
&lt;/code&gt;
&lt;/pre&gt;</body>
  <created-at type="datetime">2009-11-26T05:06:01-08:00</created-at>
  <id type="integer">335895</id>
  <permalink>solr-http-authentication</permalink>
  <repository-id type="integer">14335</repository-id>
  <title>solr http Authentication</title>
  <updated-at type="datetime">2009-09-25T03:53:56-07:00</updated-at>
  <user-id type="integer">76195</user-id>
</wiki>
