2022-05-21 19:58:09 +02:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "Uri.h"
|
|
|
|
|
|
|
|
namespace Net
|
|
|
|
{
|
|
|
|
Uri::Uri(const char* Url)
|
2022-05-21 21:51:35 +02:00
|
|
|
: Uri(String(Url))
|
2022-05-21 19:58:09 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-05-21 21:51:35 +02:00
|
|
|
Uri::Uri(const String& Url)
|
2022-05-21 19:58:09 +02:00
|
|
|
: InternetPort(InternetPortType::Default), Host(""), Path("")
|
|
|
|
{
|
|
|
|
this->ParseUri(Url);
|
|
|
|
}
|
|
|
|
|
2022-05-21 21:51:35 +02:00
|
|
|
String Uri::GetUrl()
|
2022-05-21 19:58:09 +02:00
|
|
|
{
|
|
|
|
auto Base = (InternetPort == InternetPortType::Http) ? "http://" : "https://";
|
|
|
|
|
|
|
|
return Base + Host + Path;
|
|
|
|
}
|
|
|
|
|
2022-05-21 21:51:35 +02:00
|
|
|
void Uri::ParseUri(const String& Url)
|
2022-05-21 19:58:09 +02:00
|
|
|
{
|
|
|
|
auto LowerCaseUrl = Url.ToLower();
|
|
|
|
uint32_t ParsePoint = 0;
|
|
|
|
|
|
|
|
if (LowerCaseUrl.StartsWith("https://"))
|
|
|
|
{
|
|
|
|
this->InternetPort = InternetPortType::Https;
|
|
|
|
ParsePoint = 8;
|
|
|
|
}
|
|
|
|
else if (LowerCaseUrl.StartsWith("http://"))
|
|
|
|
{
|
|
|
|
this->InternetPort = InternetPortType::Http;
|
|
|
|
ParsePoint = 7;
|
|
|
|
}
|
|
|
|
else if (LowerCaseUrl.StartsWith("//"))
|
|
|
|
{
|
|
|
|
ParsePoint = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto PathStart = Url.IndexOf("/", ParsePoint);
|
|
|
|
|
2022-05-21 21:51:35 +02:00
|
|
|
if (PathStart != String::InvalidPosition)
|
2022-05-21 19:58:09 +02:00
|
|
|
{
|
2022-05-21 21:51:35 +02:00
|
|
|
this->Host = Url.SubString(ParsePoint, PathStart - ParsePoint);
|
|
|
|
this->Path = Url.SubString(PathStart + 1);
|
2022-05-21 19:58:09 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-05-21 21:51:35 +02:00
|
|
|
this->Host = Url.SubString(ParsePoint);
|
2022-05-21 19:58:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|