2using System.Collections.Generic;
3using System.Runtime.ExceptionServices;
5using System.Threading.Tasks;
22 private readonly
object synchObj =
new object();
54 public Task<string>
GetUrl(EventHandlerAsync<PostBackEventArgs> Callback,
object State)
61 if (this.queries is
null)
64 this.queries.Removed += this.Queries_Removed;
67 this.queries[Key] =
new KeyValuePair<EventHandlerAsync<PostBackEventArgs>,
object>(Callback, State);
68 this.queries[
string.Empty] =
new KeyValuePair<EventHandlerAsync<PostBackEventArgs>,
object>(
null,
null);
71 StringBuilder Url =
new StringBuilder();
74 Url.Append(
"https://");
87 return Task.FromResult(Url.ToString());
90 private Task Queries_Removed(
object Sender,
CacheItemEventArgs<
string, KeyValuePair<EventHandlerAsync<PostBackEventArgs>,
object>> e)
94 if (!(this.queries is
null) && this.queries.
Count == 0)
101 return Task.CompletedTask;
116 if (
string.IsNullOrEmpty(ContentType) || Array.IndexOf(Content.Binary.BinaryCodec.BinaryContentTypes, ContentType) < 0)
120 if (
string.IsNullOrEmpty(From))
123 string To = Request.
Header[
"Origin"];
124 if (
string.IsNullOrEmpty(To))
128 string EndpointReference;
129 string SymmetricCipherReference;
132 if (!
string.IsNullOrEmpty(Referer) && (i = Referer.IndexOf(
':')) >= 0)
134 EndpointReference = Referer.Substring(0, i);
135 SymmetricCipherReference = Referer.Substring(i + 1);
139 EndpointReference =
string.Empty;
140 SymmetricCipherReference =
string.Empty;
144 if (
string.IsNullOrEmpty(Key))
147 Key = Key.Substring(1);
149 KeyValuePair<EventHandlerAsync<PostBackEventArgs>,
object> Rec;
153 if (this.queries is
null || !this.queries.
TryGetValue(Key, out Rec))
157 Request.DataStream.Position = 0;
164 Task _ = Task.Run(() => this.Process(Data, Response, Rec.Key, Rec.Value, From, To, EndpointReference, SymmetricCipherReference));
169 ExceptionDispatchInfo.Capture(ex).Throw();
173 private async Task Process(
TemporaryStream Data,
HttpResponse Response, EventHandlerAsync<PostBackEventArgs> Callback,
object State,
174 string From,
string To,
string EndpointReference,
string SymmetricCipherReference)
179 await Callback(
this,
new PostBackEventArgs(Data, State, From, To, EndpointReference, SymmetricCipherReference));
181 Response.StatusCode = 200;
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.
Static class managing the runtime environment of the IoT Gateway.
static CaseInsensitiveString Domain
Domain name.
static HttpServer HttpServer
HTTP Server
static byte[] NextBytes(int NrBytes)
Generates an array of random bytes.
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
Base class for all asynchronous HTTP resources. An asynchronous resource responds outside of the meth...
Represents an HTTP request.
Stream DataStream
Data stream, if data is available, or null if data is not available.
HttpRequestHeader Header
Request header.
bool HasData
If the request has data.
string SubPath
Sub-path. If a resource is found handling the request, this property contains the trailing sub-path o...
string ResourceName
Name of resource.
Represets a response of an HTTP client request.
async Task DisposeAsync()
Closes the connection and disposes of all resources.
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
Implements an HTTP server.
int[] OpenHttpsPorts
HTTPS Ports successfully opened.
const int DefaultHttpsPort
Default HTTPS port (443).
The server has not found anything matching the Request-URI. No indication is given of whether the con...
Event arguments for post-back events or callbacks.
Implements an in-memory cache.
void Dispose()
IDisposable.Dispose
int Count
Number of items in cache
bool TryGetValue(KeyType Key, out ValueType Value)
Tries to get a value from the cache.
Event arguments for cache item removal events.
Manages a temporary stream. Contents is kept in-memory, if below a memory threshold,...
override void Dispose(bool disposing)
Releases the unmanaged resources used by the System.IO.Stream and optionally releases the managed res...
Allows senders to send XMPP stanzas over HTTP POST.
bool AllowsPOST
If the POST method is allowed.
override bool UserSessions
If the resource uses user sessions.
override bool HandlesSubPaths
If the resource handles sub-paths.
XmppOverHttp(string ResourceName)
Allows senders to send XMPP stanzas over HTTP POST.
async Task POST(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
Task< string > GetUrl(EventHandlerAsync< PostBackEventArgs > Callback, object State)
Gets a Post-back URL
POST Interface for HTTP resources.
Interface for HTTP(S) Post-back resources. These can be used to allow HTTPX servers to HTTP POST back...