Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
not_found handler shouldn't care about the as header
Browse files Browse the repository at this point in the history
  • Loading branch information
blampe committed Aug 26, 2015
1 parent d45c3e5 commit 99804e7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Changes by Version
0.16.1 (unreleased)
-------------------

- Nothing changed yet.
- Fixed a bug where the 'not found' handler would incorrectly return
serialization mismatch errors..

This comment has been minimized.

Copy link
@abhinav

abhinav Aug 26, 2015

Contributor

..

"."



0.16.0 (2015-08-25)
Expand Down
2 changes: 1 addition & 1 deletion tchannel/schemes/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __call__(self, service, endpoint, body=None, headers=None,
:param string headers:
A raw headers block to provide to the endpoint.
:param int timeout:
How long to wait before raising a ``TimeoutError`` - this
How long to wait (in ms) before raising a ``TimeoutError`` - this
defaults to ``tchannel.glossary.DEFAULT_TIMEOUT``.
:param string retry_on:
What events to retry on - valid values can be found in
Expand Down
2 changes: 1 addition & 1 deletion tchannel/schemes/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __call__(self, service, endpoint, body=None, headers=None,
:param string headers:
A raw headers block to provide to the endpoint.
:param int timeout:
How long to wait before raising a ``TimeoutError`` - this
How long to wait (in ms) before raising a ``TimeoutError`` - this
defaults to ``tchannel.glossary.DEFAULT_TIMEOUT``.
:param string retry_on:
What events to retry on - valid values can be found in
Expand Down
11 changes: 9 additions & 2 deletions tchannel/tornado/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,20 @@ def handle_call(self, request, connection):
tchannel.event_emitter.fire(EventType.before_receive_request, request)

handler = self.handlers.get(request.endpoint)

if handler is None:
handler = self.handlers[self.FALLBACK]

if request.headers.get('as', None) != handler.req_serializer.name:
requested_as = request.headers.get('as', None)
expected_as = handler.req_serializer.name

if request.endpoint in self.handlers and requested_as != expected_as:
connection.send_error(
ErrorCode.bad_request,
"Invalid arg scheme in request header",
"Your serialization was '%s' but the server expected '%s'" % (
requested_as,
expected_as,
),
request.id,
)
raise gen.Return(None)
Expand Down
24 changes: 22 additions & 2 deletions tests/test_tchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,19 +233,39 @@ def endpoint(request):

@pytest.mark.gen_test
@pytest.mark.call
def test_endpoint_not_found():
def test_endpoint_not_found_with_raw_request():
server = TChannel(name='server')
server.listen()

tchannel = TChannel(name='client')

with pytest.raises(errors.BadRequestError):
with pytest.raises(errors.BadRequestError) as e:
yield tchannel.raw(
service='server',
hostport=server.hostport,
endpoint='foo',
)

assert "Endpoint 'foo' is not defined" in e.value


@pytest.mark.gen_test
@pytest.mark.call
def test_endpoint_not_found_with_json_request():
server = TChannel(name='server')
server.listen()

tchannel = TChannel(name='client')

with pytest.raises(errors.BadRequestError) as e:
yield tchannel.json(
service='server',
hostport=server.hostport,
endpoint='foo',
)

assert "Endpoint 'foo' is not defined" in e.value


def test_event_hook_register():
server = TChannel(name='server')
Expand Down

1 comment on commit 99804e7

@abhinav
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.