Skip to content

Commit e2ab7ea

Browse files
committed
Adding a third return value from connection.perform_request - headers
This will be used to implement deserializing based on mimetype
1 parent be9acfa commit e2ab7ea

File tree

8 files changed

+13
-13
lines changed

8 files changed

+13
-13
lines changed

Changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Changelog
1313
* `helpers.bulk` and `helpers.streaming_bulk` are no longer limitted to just
1414
index operations.
1515
* unicode body (for `incices.analyze` for example) is now handled correctly
16+
* changed `perform_request` on `Connection` classes to return headers as well.
17+
This is a backwards incompatible change for people who have developed their own
18+
connection class.
1619

1720
0.4.3
1821
-----

elasticsearch/connection/http_requests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ def perform_request(self, method, url, params=None, body=None, timeout=None, ign
5858

5959
self.log_request_success(method, url, response.request.path_url, body, response.status_code, raw_data, duration)
6060

61-
return response.status_code, raw_data
61+
return response.status_code, response.headers, raw_data

elasticsearch/connection/http_urllib3.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,5 @@ def perform_request(self, method, url, params=None, body=None, timeout=None, ign
5757
self.log_request_success(method, full_url, url, body, response.status,
5858
raw_data, duration)
5959

60-
return response.status, raw_data
61-
62-
60+
return response.status, response.getheaders(), raw_data
6361

elasticsearch/connection/memcached.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def perform_request(self, method, url, params=None, body=None, timeout=None, ign
7777
self.log_request_success(method, full_url, url, body, status,
7878
response, duration)
7979

80-
return status, response
80+
return status, {}, response
8181

8282

8383

elasticsearch/connection/thrift.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,5 @@ def perform_request(self, method, url, params=None, body=None, timeout=None, ign
7373
self.log_request_success(method, url, url, body, response.status,
7474
response.body, duration)
7575

76-
return response.status, response.body
77-
78-
76+
return response.status, response.headers or {}, response.body
7977

elasticsearch/transport.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def sniff_hosts(self):
154154
for c in self.connection_pool.connections + self.seed_connections:
155155
try:
156156
# use small timeout for the sniffing request, should be a fast api call
157-
_, node_info = c.perform_request('GET', '/_cluster/nodes', timeout=.1)
157+
_, headers, node_info = c.perform_request('GET', '/_cluster/nodes', timeout=.1)
158158
node_info = self.serializer.loads(node_info)
159159
break
160160
except (ConnectionError, SerializationError):
@@ -251,7 +251,7 @@ def perform_request(self, method, url, params=None, body=None):
251251
connection = self.get_connection()
252252

253253
try:
254-
status, raw_data = connection.perform_request(method, url, params, body, ignore=ignore)
254+
status, headers, raw_data = connection.perform_request(method, url, params, body, ignore=ignore)
255255
except ConnectionError:
256256
self.mark_dead(connection)
257257

test_elasticsearch/test_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def _dummy_send(*args, **kwargs):
6262
return con
6363

6464
def _get_request(self, connection, *args, **kwargs):
65-
status, data = connection.perform_request(*args, **kwargs)
65+
status, headers, data = connection.perform_request(*args, **kwargs)
6666
self.assertEquals(200, status)
6767
self.assertEquals(u'{}', data)
6868

@@ -129,7 +129,7 @@ def test_failed_request_logs_and_traces(self, logger, tracer):
129129
@patch('elasticsearch.connection.base.logger')
130130
def test_success_logs_and_traces(self, logger, tracer):
131131
con = self._get_mock_connection(response_body='''{"answer": "that's it!"}''')
132-
status, data = con.perform_request('GET', '/', {'param': 42}, '''{"question": "what's that?"}''')
132+
status, headers, data = con.perform_request('GET', '/', {'param': 42}, '''{"question": "what's that?"}''')
133133

134134
# trace request
135135
self.assertEquals(1, tracer.info.call_count)

test_elasticsearch/test_transport.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ class DummyConnection(Connection):
1111
def __init__(self, **kwargs):
1212
self.exception = kwargs.pop('exception', None)
1313
self.status, self.data = kwargs.pop('status', 200), kwargs.pop('data', '{}')
14+
self.headers = kwargs.pop('headers', {})
1415
self.calls = []
1516
super(DummyConnection, self).__init__(**kwargs)
1617

1718
def perform_request(self, *args, **kwargs):
1819
self.calls.append((args, kwargs))
1920
if self.exception:
2021
raise self.exception
21-
return self.status, self.data
22+
return self.status, self.headers, self.data
2223

2324
CLUSTER_NODES = '''{
2425
"ok" : true,

0 commit comments

Comments
 (0)