4using System.Threading.Tasks;
35 private class UrlRecord
38 public bool OneTimeUse;
70 if (s.StartsWith(
"/"))
73 if (
string.IsNullOrEmpty(s))
79 if (!(shortUrls?.TryGetValue(s, out UrlRecord Rec) ??
false))
90 StringBuilder sb =
new StringBuilder(Rec.Url);
91 bool First = Rec.Url.IndexOf(
'?') < 0;
103 sb.Append(
System.Web.HttpUtility.UrlEncode(P.Key));
105 sb.Append(
System.Web.HttpUtility.UrlEncode(P.Value));
129 if (!(Content.
Decoded is Dictionary<string, object> Obj) ||
130 !Obj.TryGetValue(
"Url", out
object Obj2) ||
131 !(Obj2 is
string Url) ||
132 !Obj.TryGetValue(
"OneTimeUse", out Obj2) ||
133 !(Obj2 is
bool OneTimeUse))
158 while (shortUrls?.ContainsKey(Id) ??
false);
160 shortUrls?.Add(Id,
new UrlRecord()
163 OneTimeUse = OneTimeUse
Static class that does BASE64URL encoding (using URL and filename safe alphabet), as defined in RFC46...
static string Encode(byte[] Data)
Converts a binary block of data to a Base64URL-encoded string.
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
Exception Error
Error response.
Static class managing the runtime environment of the IoT Gateway.
static byte[] NextBytes(int NrBytes)
Generates an array of random bytes.
static string GetUrl(string LocalResource)
Gets a URL for a resource.
Web Service for working with short URLs.
bool AllowsGET
If the GET method is allowed.
static string GetShortUrl(string Url, bool OneTimeUse)
Shortens a URL temporarily. Shortened URLs are available at most for 24 hours (if used) and 1h if not...
UrlShortener(string ResourceName)
Web Service, generating QR-codes based on URI input.
override bool UserSessions
If the resource uses user sessions.
async Task GET(HttpRequest Request, HttpResponse Response)
Executes the GET method on the resource.
bool AllowsPOST
If the POST method is allowed.
UrlShortener()
Web Service, generating QR-codes based on URI input.
async Task POST(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
override bool HandlesSubPaths
If the resource handles sub-paths.
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
Represents an HTTP request.
HttpRequestHeader Header
Request header.
string SubPath
Sub-path. If a resource is found handling the request, this property contains the trailing sub-path o...
async Task< ContentResponse > DecodeDataAsync()
Decodes data sent in request.
string ResourceName
Name of resource.
Represets a response of an HTTP client request.
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
Task Return(Exception ex)
Returns an error to the client.
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
The requested resource has been assigned a new permanent URI and any future references to this resour...
The server has not found anything matching the Request-URI. No indication is given of whether the con...
Implements an in-memory cache.
GET Interface for HTTP resources.
POST Interface for HTTP resources.