diff --git a/lib/solr/connection.rb b/lib/solr/connection.rb index 963d136..28c10aa 100755 --- a/lib/solr/connection.rb +++ b/lib/solr/connection.rb @@ -140,7 +140,7 @@ def send(request) def post(request) response = @connection.post(@url.path + "/" + request.handler, request.to_s, - { "Content-Type" => request.content_type }) + build_headers({"Content-Type" => request.content_type}) case response when Net::HTTPSuccess then response.body @@ -158,5 +158,14 @@ def create_and_send_query(klass, options = {}, &action) return response unless action response.each {|hit| action.call(hit)} end - -end + + # build headers + def build_headers(header) + authorization_header.update(header) + end + + # generate http basic authentication header + def authorization_header + (@user || @password ? { 'Authorization' => 'Basic ' + ["#{@user}:#{ @password}"].pack('m').delete("\r\n") } : {}) + end +end \ No newline at end of file