The latest RC4 makes it easy to change the connection class (#1407282: Allow alternative solrConnection class) which makes it quite easy to provide custom/automatic connection information, but I ran into a limitation of SearchApiSolrConnection which provides the wrapper for drupal_http_request() which makes the necessary connection to the Solr service. Basically, I need to provide a custom Stream Wrapper Context (http://php.net/manual/en/stream.contexts.php) to connect to Solr using a local certificate instead of a username/password.

It would be great if Search API Solr provided a way for a custom connection class to pass along context information which can be passed through to drupal_http_request().

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

populist’s picture

Status: Active » Needs review
FileSize
1.28 KB

Here is a patch that provides a programatic way to inject stream context into the drupal_http_request() made by SearchApiSolrConnection to connect to the Solr service. It provides two things:

1.) A basic modification to makeHttpRequest() which, if there is a context defined, will pass it along to drupal_http_request() in the $options.

2.) Documentation in the README that explains how the configuration would work if you need to use custom Stream Wrapper Context.

This won't effect anyone's existing Search API implementation, but will allow for use cases where you need to do fancy Stream Context things.

drunken monkey’s picture

Status: Needs review » Needs work

Thanks, this seems like a justified feature request. However, the implementation is a bit too "dirty". It doesn't need to be in the README.txt, you can just include documentation in the service class (and the interface) itself.
Please just exactly copy the style of the soft_commit setting (i.e., property, getter, setter). Also, while you're at it, please also add the getter and setter of the soft_commit setting to the interface (where it seems I've missed it).

populist’s picture

Status: Needs work » Needs review
FileSize
2.38 KB

Sounds good. Here is a new patch that:

1.) Adds a setStreamContext and getStreamContext setting to the interface similar to how the soft_commit setting works. This makes it quite easy to do a $this->setStreamContext($stream_context) in your connection class to handle custom stream context operations.

2.) Updates the way $soft_commit gets called from $this->soft_commit to $this->getSoftCommit() as requested in #2

drunken monkey’s picture

Version: 7.x-1.0-rc4 » 7.x-1.x-dev
Category: task » feature
Status: Needs review » Fixed

2.) Updates the way $soft_commit gets called from $this->soft_commit to $this->getSoftCommit() as requested in #2

This is not what I meant. Inside the class, accessing the properties directly is (usually) fine. You also don't have to use getStreamContext() there.
What I meant was to add those for methods, the getters and setters for soft_commit and stream_context to the SearchApiSolrConnectionInterface interface, so they are properly documented and can be relied on to be present.

Anyways, I've now changed that myself and also fixed the documentation according to Drupal's guidelines.
And, since I'm pretty sure that this patch won't break anything and work fine, I already committed it.
Thanks again for the suggestion and your work in this issue!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.