Skip to content

fix: strip trailing slashes in BaseService.set_service_url#130

Merged
padamstx merged 1 commit into
mainfrom
fix-service-url
Nov 15, 2021
Merged

fix: strip trailing slashes in BaseService.set_service_url#130
padamstx merged 1 commit into
mainfrom
fix-service-url

Conversation

@padamstx
Copy link
Copy Markdown
Contributor

This commit modifies the BaseService.set_service_url()
function so that it removes any trailing slashes.

Previously, a service URL containing a trailing slash
(e.g. "https://myserver.com/api/v1/") would result in a
request URL that contains two slashes between the service URL
and the operation path (e.g. "https://myserver.com/api/v1//myoperationpath"),
and some server implementations might fail to process such
a request properly.

With the changes in this commit, a request URL of
"https://myserver.com/api/v1/myoperationpath" will be used instead.

This commit modifies the BaseService.set_service_url()
function so that it removes any trailing slashes.

Previously, a service URL containing a trailing slash
(e.g. "https://myserver.com/api/v1/") would result in a
request URL that contains two slashes between the service URL
and the operation path (e.g. "https://myserver.com/api/v1//myoperationpath"),
and some server implementations might fail to process such
a request properly.

With the changes in this commit, a request URL of
"https://myserver.com/api/v1/myoperationpath" will be used instead.
@padamstx padamstx requested a review from rmkeezer November 11, 2021 23:55
Comment thread test/test_base_service.py
'data') == b'{"hello": "world", "f\\u00f3\\u00f3": "b\\u00e5r"}'


def test_trailing_slash():
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

moved this to test_utils.py

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 11, 2021

Codecov Report

Merging #130 (7ad297f) into main (1e29bfa) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #130   +/-   ##
=======================================
  Coverage   99.66%   99.66%           
=======================================
  Files          24       24           
  Lines         906      908    +2     
=======================================
+ Hits          903      905    +2     
  Misses          3        3           
Impacted Files Coverage Δ
ibm_cloud_sdk_core/base_service.py 99.48% <100.00%> (+<0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1e29bfa...7ad297f. Read the comment docs.

Comment thread test/test_base_service.py
assert strip_extra_slashes('https://host/path//') == 'https://host/path/'
assert strip_extra_slashes('https://host//path//') == 'https://host//path/'

def test_service_url_handling():
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the direct calls to strip_extra_slashes() so this test will focus on the service and service_url

Comment thread test/test_base_service.py
url='/path/',
headers={'X-opt-out': True},
data={'hello': 'world'})
assert req.get('url') == 'https://host//path/'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we can no longer have double-slashes between the service_url and the operation path

@padamstx
Copy link
Copy Markdown
Contributor Author

padamstx commented Nov 11, 2021

Reminder to myself: before we merge this, we need to test this version of the core with existing generated unit tests.

Edit: The platform-services python SDK's unit tests ran clean using my local copy of the python core.

@padamstx
Copy link
Copy Markdown
Contributor Author

I also did a test with the platform-services python SDK where I ran the global-search integration test with and without the python core fix.
The service URL I used in each case was: https://api.global-search-tagging.cloud.ibm.com/.
In the "before" scenario (without the python core fix), I see this in the http debug messages:

send: b'POST //v3/resources/search?limit=1 HTTP/1.1\r\nHost: api.global-search-tagging.cloud.ibm.com

so the path value passed in the HTTP request message does in fact have a leading double-slash (the global-search server still processes this request just fine, but not all servers behave this way).

In the "after" scenario (with the python core fix), I see this in the http debug messages:

send: b'POST /v3/resources/search?limit=1 HTTP/1.1\r\nHost: api.global-search-tagging.cloud.ibm.com

so the path value now has just a single slash.

Copy link
Copy Markdown
Contributor

@rmkeezer rmkeezer left a comment

Choose a reason for hiding this comment

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

LGTM

@padamstx padamstx self-assigned this Nov 12, 2021
@padamstx padamstx merged commit 37d0099 into main Nov 15, 2021
@padamstx padamstx deleted the fix-service-url branch November 15, 2021 15:39
ibm-devx-sdk pushed a commit that referenced this pull request Nov 15, 2021
## [3.13.1](v3.13.0...v3.13.1) (2021-11-15)

### Bug Fixes

* strip trailing slashes in BaseService.set_service_url ([#130](#130)) ([37d0099](37d0099))
@ibm-devx-sdk
Copy link
Copy Markdown

🎉 This PR is included in version 3.13.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants