我们正在使用sunspot-rails连接到websolr。我试图找到一种方法来将http标头添加到传出请求。样本仅适用于rsolr,但不适用于太阳黑子轨道。(https://github.com/onemorecloud/websolr-demo-advanced-auth)。
目的是使用标头进行身份验证。有没有办法在sunspot-rails中为索引和查询调用添加/修改http标头?
答案 0 :(得分:0)
outoftime引用的示例将是检索http对象的解决方案。
class SolrConnectionFactoryWithTimeout
def initialize(timeout = 60)
@timeout = timeout
end
def connect(opts = {})
client = RSolr.connect(opts)
solr_connection = client.connection
http = solr_connection.connection
http.read_timeout = @timeout
client
end
end
Sunspot::Session.connection_class =
SolrConnectionFactoryWithTimeout.new(timeout.to_f)
然后与...结合使用 http://ruby-doc.org/stdlib-2.0/libdoc/net/http/rdoc/Net/HTTP.html#label-Setting+Headers
req = Net::HTTP::Get.new(uri)
req['If-Modified-Since'] = file.mtime.rfc2822