Skip to content

Commit

Permalink
Merge pull request RasaHQ#3824 from RasaHQ/endpoints_urls_with_slash
Browse files Browse the repository at this point in the history
Endpoints urls with slash
  • Loading branch information
erohmensing authored Jun 20, 2019
2 parents e27d778 + 2334669 commit 8c04bae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Changed

Removed
-------
- revert the stripping of trailing slashes in endpoint URLs since this can lead to
problems in case the trailing slash is actually wanted

Fixed
-----
Expand Down
8 changes: 7 additions & 1 deletion rasa/utils/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ def concat_url(base: Text, subpath: Optional[Text]) -> Text:
`base`."""

if not subpath:
return base.rstrip("/")
if base.endswith("/"):
logger.debug(
"The URL '{}' has a trailing slash. Please make sure the "
"target server supports trailing slashes for this "
"endpoint.".format(base)
)
return base

url = base
if not base.endswith("/"):
Expand Down
14 changes: 12 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

import pytest
from aioresponses import aioresponses

Expand Down Expand Up @@ -100,11 +102,19 @@ def test_validate_yaml_schema_raise_exception(file, schema):
[
("https://example.com", None, "https://example.com"),
("https://example.com/test", None, "https://example.com/test"),
("https://example.com/", None, "https://example.com"),
("https://example.com//", None, "https://example.com"),
("https://example.com/", None, "https://example.com/"),
("https://example.com/", "test", "https://example.com/test"),
("https://example.com/", "test/", "https://example.com/test/"),
],
)
def test_concat_url(base, subpath, expected_result):
assert concat_url(base, subpath) == expected_result


def test_warning_for_base_paths_with_trailing_slash(caplog):
test_path = "base/"

with caplog.at_level(logging.DEBUG):
assert concat_url(test_path, None) == test_path

assert len(caplog.records) == 1

0 comments on commit 8c04bae

Please sign in to comment.