1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

URL: Add getOrigin()

This commit is contained in:
attila 2023-09-17 00:16:22 +02:00 committed by Anthony Nicholls
parent eb03fbc989
commit ee14a5ea55
2 changed files with 19 additions and 0 deletions

View file

@ -448,6 +448,18 @@ int URL::getPort() const
return colonPos > 0 ? url.substring (colonPos + 1).getIntValue() : 0;
}
String URL::getOrigin() const
{
const auto schemeAndDomain = getScheme() + "://" + getDomain();
const auto colonPos = url.indexOfChar (URLHelpers::findStartOfNetLocation (url), ':');
if (colonPos > 0)
return schemeAndDomain + ":" + String { getPort() };
return schemeAndDomain;
}
URL URL::withNewDomainAndPath (const String& newURL) const
{
URL u (*this);

View file

@ -154,6 +154,13 @@ public:
*/
int getPort() const;
/** Returns the origin of a resource reachable on this URL.
In the context of cross-origin resource sharing (CORS) a script downloaded from this URL
would only be allowed to reach resources from the returned origin.
*/
String getOrigin() const;
/** Returns a new version of this URL with a different domain and path.
e.g. if the URL is "http://www.xyz.com/foo?x=1" and you call this with