Sha256: 172afd2f80781ca5243286c120ac3f6ee54a11bb9d8507ca1262fc373c558006

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

module RSolr
  module Connection
    class NetHttp
      
      def get(path, params={})
        url = build_url(path, params)
        net_http_response = basic_auth_get_request(url)
        create_http_context(net_http_response, url, path, params)
      end

      def post(path, data, params={}, headers={})
        url = build_url(path, params)
        net_http_response = basic_auth_post_request(url, data, headers)
        create_http_context(net_http_response, url, path, params, data, headers)
      end
    
    private
    
      def basic_auth_get_request(url)
        rails_logger "SOLR GET: #{url}"
        req = add_basic_auth(Net::HTTP::Get.new(url))
        connection.request(req)
      end

      def basic_auth_post_request(url, data, headers)
        rails_logger "SOLR POST: #{url}" 
        req = add_basic_auth(Net::HTTP::Post.new(url, headers))
        connection.request(req, data)
      end
      
      def add_basic_auth(req)
        req.basic_auth(uri.user, uri.password) if uri.user and uri.password
        req
      end
      
      def rails_logger(text)
        Rails.logger.debug(text) if defined?(Rails)
      end
      
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sunspot-rails-http-basic-auth-0.0.2 lib/sunspot-rails-http-basic-auth/rsolr/connection/net_http.rb
sunspot-rails-http-basic-auth-0.0.1 lib/sunspot-rails-http-basic-auth/rsolr/connection/net_http.rb