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

[core-http] URLBuilder struggles with parametrized URL and parametrized path #13159

Closed
joheredi opened this issue Jan 12, 2021 · 3 comments
Closed
Assignees
Labels
Azure.Core Client This issue points to a problem in the data-plane of the library.

Comments

@joheredi
Copy link
Member

We're facing a problem with the Tables SDK that I think I have been able to isolate to core-http's URLBuilder.

It seems like having the base URL with a path cause troubles, for example:

describe("path parameters", () => {
  it.only("Test baseUrl with parameter", () => {
    const urlBuilder = URLBuilder.parse("{url}");
    urlBuilder.appendPath("{param}");
    urlBuilder.replaceAll("{url}", "http://localhost:3000/param1");
    urlBuilder.replaceAll("{param}", "param2");
    const url = urlBuilder.toString();
    assert.strictEqual(url, "http://localhost:3000/param1/param2");
  });
});

In this example, I would expect it to end up being http://localhost:3000/param1/param2 however it turns out to dismiss the {param} and ends up as http://localhost:3000/param1

However, if the base URL doesn't have any path elements it works fine

it.only("Test baseUrl with parameter", () => {
    const urlBuilder = URLBuilder.parse("{url}");
    urlBuilder.appendPath("{param}");
    urlBuilder.replaceAll("{url}", "http://localhost:3000");
    urlBuilder.replaceAll("{param}", "param2");
    const url = urlBuilder.toString();
    assert.strictEqual(url, "http://localhost:3000/param2");
  });

The scenario in the Tables SDK where this happens is when targeting the Azure Storage Emulator, in the regular scenario where we hit the service the base url is in this format https://<ACCOUNT_NAME>.table.core.windows.net so it works fine. However when targeting the Storage Emulator we have an url like this http://localhost:10002/<ACCOUNT_NAME> so adding the Tables path in the first case is no issue, in the second scenario it runs in the issue above.

This issue seems to be the cause of #12753 and blocking support for #13118 and #13100

Unfortunately, other places seem to rely on this behavior so changing it may break other libraries. I'm filing this issue to keep track of this problem and for starting up a discussion on what improvements can be made around this.

/cc: @xirzec

@ghost ghost added the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Jan 12, 2021
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Jan 12, 2021
@joheredi joheredi added this to the Backlog milestone Jan 12, 2021
@ramya-rao-a ramya-rao-a added the Client This issue points to a problem in the data-plane of the library. label Jan 12, 2021
@ramya-rao-a ramya-rao-a modified the milestones: Backlog, [2021] February Jan 12, 2021
@jeremymeng
Copy link
Member

So when we parse "{url}", URLBuilder set its host to {url}, which isn't 100% correct as a url can contain all possible components. later after replacement the new host now contains another path component /param1. Then setting the new host will cause the old path of {param} to be overwritten in the state machine. I need to think more about this.

@xirzec
Copy link
Member

xirzec commented Jan 20, 2021

So when we parse "{url}", URLBuilder set its host to {url}, which isn't 100% correct as a url can contain all possible components. later after replacement the new host now contains another path component /param1. Then setting the new host will cause the old path of {param} to be overwritten in the state machine. I need to think more about this.

Yeah, basically if you feed URLBuilder a url that already contains a path and then set it again later it replaces it instead of concatenating it. We rely on this behavior in other client libs, so we can't just fix it directly.

@jeremymeng jeremymeng modified the milestones: [2021] February, Backlog Feb 17, 2021
@jeremymeng
Copy link
Member

Given that there's a workaround I am closing this for now.

openapi-sdkautomation bot pushed a commit to AzureSDKAutomation/azure-sdk-for-js that referenced this issue Feb 25, 2021
@xirzec xirzec removed this from the Backlog milestone May 17, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Azure.Core Client This issue points to a problem in the data-plane of the library.
Projects
None yet
Development

No branches or pull requests

4 participants