panjiwa10028 / solr-php-client

Automatically exported from code.google.com/p/solr-php-client
Other
0 stars 0 forks source link

No access to _curl #69

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I've got a usecase where i need to connect to a password protected solr server. 
This might be a rare case but it is not really special and might hit others as 
well.

Currently i have to hack the HttpTransport/Curl class:

I am setting _curl to protected and i am setting http_username/pass in a 
derived class.

This should be possible without hacks so either implement a getter or set _curl 
to protected

Original issue reported on code.google.com by andreas....@googlemail.com on 22 Aug 2011 at 10:40

GoogleCodeExporter commented 8 years ago
With existing code you can use the FileGetContents HttpTransport which supports 
basic authentication if you prepend the authentication information to the host 
when you construct the Solr Service instance (e.g "user:password@example.com"). 
But this is a happy accident with the http URL handler and not a designed use 
case.

My suggested method would be to do what you're doing, create your own 
HttpTransport implementation that you can set the authentication information on 
however you want.  For a more universal client change, we'd probably have to 
change the HttpTransport interface to care about authentication information and 
then expose it through the Service methods. Similar issues exist for people who 
want to access Solr through a forward proxy.

I'll consider any patch you want to provide, even if its just an 
AuthenticatedCurl implementation for HttpTransport.

Original comment by donovan....@gmail.com on 26 Aug 2011 at 3:02

GoogleCodeExporter commented 8 years ago
why so so complicated. i have patched Service.php to use basic auth. ok, it 
would be great to have an option outside to define all the stuff but at the 
moment it works.

in Service.php

    public function __construct($host = 'localhost', $port = 8180, $path = '/solr/', $auth = '')
    {
        $this->setHost($host);
        $this->setPort($port);
        $this->setPath($path);

        $this->_initUrls();

        // create our shared get and post stream contexts
        // $this->_getContext = stream_context_create();
        // sg324

        if (!empty($auth)) {
            $this->_getContext = stream_context_create(array(
                'http' => array(
                    'header'  => "Authorization: Basic " . base64_encode("isys:isys2go")
                )
            ));
        } else {
            $this->_getContext = stream_context_create();
        }

now you can call 

$solr = new Apache_Solr_Service($solrServer, $solrServer, $solrServer, 
'user:secret');

we only use SolrPhpClient for searching and not for indexing. so this patch 
works for us. but the post can easily be adopted.

markus

Original comment by mrietz...@gmail.com on 30 Nov 2011 at 12:47

GoogleCodeExporter commented 8 years ago
i just have seen that we use r22 and there are new versions available.
think you could easily patch the latest version r60. FileGetContents should 
work here, also it has to be done a bit more coding as the auth must be 
supported with/all the transports (Curl etc).

markus

Original comment by mrietz...@gmail.com on 30 Nov 2011 at 1:13

GoogleCodeExporter commented 8 years ago
Work to support basic authentication more directly has been started in issue 
#81 and r64.  This issue wasn't actually a duplicate, but i'm going to merge 
them like they were.

Original comment by donovan....@gmail.com on 5 Jul 2012 at 9:19