Commits

Simon Cross  committed c7475e8

Add support for a custom prefix to util.build_rest_path. Fix bug in RiakSearch.get_decoder content_type look up. Use POST instead of PUT for RiakSearch .add and .delete commands. Don't leak HTTP responses out via the API from .add and .delete commands.

  • Participants
  • Parent commits b2da0c5

Comments (0)

Files changed (2)

File txriak/search.py

         self._decoders = {"text/xml": ElementTree.fromstring}
 
     def get_decoder(self, content_type):
-        decoder = self._client.get_decoder(content_type) or self._decoders[content_type]
+        decoder = self._client.get_decoder(content_type) or self._decoders.get(content_type)
         if not decoder:
             decoder = self.decode
 
         headers = {'Accept': 'text/xml, */*; q=0.5',
                    'Content-Type': 'text/xml',
                    }
-        return util.http_request_deferred('PUT', self._host, self._port, url,
-                                           headers, xml.toxml())
+        d = util.http_request_deferred('POST', self._host, self._port, url,
+                                       headers, xml.toxml())
+        d.addCallback(lambda response: response[0]['http_code'] == 200)
+        return d
 
     def add(self, index, *docs):
         xml = Document()
             return decoder(data)
 
         url = "/solr/%s/select" % index
-        d = util.http_request_deferred('GET', self._host, self._port, url)
+        host, port, url = util.build_rest_path(self._client, prefix=url,
+                                               params=options)
+        d = util.http_request_deferred('GET', host, port, url)
         d.addCallback(decode_results)
         return d
 

File txriak/util.py

         return default_value
 
 def build_rest_path(client,
-                    bucket=None, key=None, spec=None, params=None):
+                    bucket=None, key=None, spec=None, params=None,
+                    prefix=None):
     """
     Given a RiakClient, RiakBucket, Key, LinkSpec, and Params,
     construct and return a URL.
     """
     # Build 'http://hostname:port/prefix/bucket'
     path = ''
-    path += '/' + client._prefix
+    path += '/' + (prefix or client._prefix)
 
     # Add '.../bucket'
     if bucket: