Skip to content

Commit

Permalink
Merge e3db354 into ea4fe25
Browse files Browse the repository at this point in the history
  • Loading branch information
djmaze committed Jul 8, 2018
2 parents ea4fe25 + e3db354 commit 337c516
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/actions/action_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class HttpAction(Action):
def __init__(self, target, method='POST', headers=None, body=None, json=False, fail_on_error=False,
output='HTTP {{ response.status_code }} : {{ response.content }}'):

self.target = target
self.target = self._render_with_template(target)
self.method = method
self.headers = headers
self.body = body
Expand All @@ -23,13 +23,17 @@ def _run(self):
if self.body and 'Content-Length' not in headers:
headers['Content-Length'] = str(len(self.body))

response = requests.request(self.method, self.target, headers=headers, data=self._body)
response = requests.request(self.method, self._target, headers=headers, data=self._body)

if self.fail_on_error and response.status_code // 100 != 2:
self.error('HTTP call failed (HTTP %d)' % response.status_code)

print(self._render_with_template(self.output_format, response=response))

@property
def _target(self):
return self._render_with_template(self.target)

@property
def _headers(self):
headers = dict()
Expand Down
6 changes: 6 additions & 0 deletions tests/test_http_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ def test_get_method(self):
self.assertIn('H accept=text/plain', output)
self.assertIn('H x-test=test_get_method', output)

def test_target_replacement(self):
output = self._invoke_http(
target='/some/{{ "remote" }}/endpoint')

self.assertIn('uri=/some/remote/endpoint', output)

def test_header_replacement(self):
output = self._invoke_http(
headers={'X-Original-Path': '{{ request.path }}'})
Expand Down

0 comments on commit 337c516

Please sign in to comment.