Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #2965 - modify getRequestBaseUri logic #2966

Merged
merged 2 commits into from
Nov 10, 2021
Merged

issue #2965 - modify getRequestBaseUri logic #2966

merged 2 commits into from
Nov 10, 2021

Conversation

lmsurpre
Copy link
Member

@lmsurpre lmsurpre commented Nov 9, 2021

Previously, we looked for the last instance of /[resourceType] in the path and assumed that was the first thing after the baseUrl. However, if a resourceId happened to match the resource type, this proved erroneous.

The updated logic looks for the first instance of /[resourceType]/ in the path instead.
If that doesn't exist, then we fall back to the old approach of using the last index of /[resourceType] (and because we now know there was no /[resourceType]/ segment before this, this approach should now be safe).

This updated logic could break if someone insisted on using a baseUrl that includes a path segment that matches /[resourceType]/ (e.g. https://example.com/my/Patient/api/ ) but I think that is an acceptable risk because that would be very dumb to do. We could even add that guidance to the docs if we feel its needed.

Signed-off-by: Lee Surprenant lmsurpre@us.ibm.com

Previously, we looked for the last instnace of `/[resourceType]` in the
path and assumed that was the first thing after the baseUrl. However, if
a resourceId happened to match the resource type, this proved erroneous.

The updated logic looks for the first instance of `/[resourceType]/` in
the path instead.
If that doesn't exist, then we fall back to the old approach of using
the last index of `/[resourceType]` (now that we know it should be safe
to do so).

This updated logic could break if someone insisted on including a
baseUrl that includes a path segment that matches `/[resourceType]/`
(e.g. https://example.com/my/Patient/api/ ) but I think that is an
acceptable risk because that would be very dumb to do.

Alternatives would be to either
A. rely solely on a configured baseUrl; or
B. do more processing of the URL to ensure we're stripping a path and
not a hostname

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
@lmsurpre lmsurpre changed the title issue #2965 - use the first instance of /resourceType and not the last issue #2965 - modify getRequestBaseUri logic Nov 10, 2021
Copy link
Contributor

@michaelwschroeder michaelwschroeder left a comment

Choose a reason for hiding this comment

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

LGTM

and add a test to OriginalRequestRewriteServerTest for the exact
examples used in the docs

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
@lmsurpre lmsurpre merged commit 44b0d80 into main Nov 10, 2021
@lmsurpre lmsurpre deleted the issue-2965 branch November 10, 2021 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants