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.
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:
This produces the correct URL text
http://api.thingspeak.com/update
with the default scheme, butgetPort()
incorrectly returns 0.See https://github.com/SmingHub/Sming/issues/1937#issuecomment-549534674, PR #1945 provided a fix but didn't actually resolve the underlying issue.
Url::toString() doesn't lowercase scheme
For example:
Incorrectly produces
HTTP://api.thingspeak.com/update
.Add
Url::getQueryParameter
methodCare is required when reading query parameters as direct access to the
Query
member variable means non-existent keys get added. Therefore aconst
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.