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

Fixes to Url default handling and query parameters #2828

Merged
merged 3 commits into from
Jun 23, 2024

Conversation

mikee47
Copy link
Contributor

@mikee47 mikee47 commented Jun 23, 2024

This PR addresses some inconsistencies with the Url class.

Ensure Url provides default port for default scheme

When building a URL the Scheme defaults to HTTP if not specified.
This means the port should also default to 80, but it doesn't.

For example:

Url url;
url.Host = "api.thingspeak.com";
url.Path = "/update";

This produces the correct URL text http://api.thingspeak.com/update with the default scheme, but getPort() incorrectly returns 0.

See #1937 (comment),
PR #1945 provided a fix but didn't actually resolve the underlying issue.

Url::toString() doesn't lowercase scheme

For example:

Url url;
url.Scheme = "HTTP";
url.Host = "api.thingspeak.com";
url.Path = "/update";

Incorrectly produces HTTP://api.thingspeak.com/update.

Add Url::getQueryParameter method

Care is required when reading query parameters as direct access to the Query member variable means non-existent keys get added. Therefore a const cast is required. This method provides a more convenient way for safely reading values, and also allows a default to be given where the value doesn't exist.

@slaff slaff added this to the 5.2.0 milestone Jun 23, 2024
@slaff slaff merged commit b5e39d5 into SmingHub:develop Jun 23, 2024
40 checks passed
@mikee47 mikee47 deleted the fix/url-port-default branch June 23, 2024 14:21
@slaff slaff mentioned this pull request Jul 4, 2024
5 tasks
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.

2 participants