4using System.Security.Cryptography.X509Certificates;
6using System.Threading.Tasks;
72 public Task<ContentResponse>
GetAsync(Uri Uri, X509Certificate Certificate, EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
73 params KeyValuePair<string, string>[] Headers)
96 public async Task<ContentResponse>
GetAsync(Uri Uri, X509Certificate Certificate,
97 EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
int TimeoutMs, params KeyValuePair<string, string>[] Headers)
104 Rec.Encoded.Position = 0;
106 if (Rec.Encoded.Length >
int.MaxValue)
107 return new ContentResponse(
new OutOfMemoryException(
"Resource too large."));
109 byte[] Bin = await Rec.Encoded.ReadAllAsync();
129 EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator, params KeyValuePair<string, string>[] Headers)
144 EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
TemporaryStream Destination, params KeyValuePair<string, string>[] Headers)
165 EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
int TimeoutMs, params KeyValuePair<string, string>[] Headers)
167 return this.
GetTempStreamAsync(Uri, Certificate, RemoteCertificateValidator, TimeoutMs,
null, Headers);
187 EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
int TimeoutMs,
TemporaryStream Destination,
188 params KeyValuePair<string, string>[] Headers)
191 string BareJid = Uri.UserInfo +
"@" + Uri.Authority;
197 if (Proxy.DefaultXmppClient.Disposed || Proxy.ServerlessMessaging.Disposed)
200 if (
string.Compare(BareJid, Proxy.DefaultXmppClient.BareJID,
true) == 0 &&
201 Proxy.DefaultXmppClient.TryGetExtension(out
HttpxServer Server))
203 return await Server.GetLocalTempStreamAsync(Uri.PathAndQuery + Uri.Fragment, Destination);
223 return await Server.GetLocalTempStreamAsync(Uri.PathAndQuery + Uri.Fragment, Destination);
228 return new ContentStreamResponse(
new InvalidOperationException(
"No HTTPX Extesion has been registered on the XMPP Client."));
232 if (
string.IsNullOrEmpty(Uri.UserInfo))
233 FullJid = BareJid = Uri.Authority;
236 BareJid = Uri.UserInfo +
"@" + Uri.Authority;
248 LocalUrl = Uri.PathAndQuery + Uri.Fragment;
252 return new ContentStreamResponse(
new InvalidOperationException(
"An HTTPX Proxy or XMPP Client Module Parameter has not been registered."));
254 List<HttpField> Headers2 =
new List<HttpField>();
255 bool HasHost =
false;
257 foreach (KeyValuePair<string, string> Header
in Headers)
259 switch (Header.Key.ToLower())
262 Headers2.Add(
new HttpField(
"Host", BareJid));
272 Headers2.Add(
new HttpField(Header.Key, Header.Value));
278 Headers2.Add(
new HttpField(
"Host", Uri.Authority));
286 Timer =
new Timer((P) =>
288 State.Done.TrySetResult(
false);
289 },
null, TimeoutMs, Timeout.Infinite);
300 State.HttpResponse = e.HttpResponse;
301 State.StatusCode = e.StatusCode;
302 State.StatusMessage = e.StatusMessage;
306 State.File = new TemporaryStream();
308 if (!(e.Data is null))
310 await State.File.WriteAsync(e.Data, 0, e.Data.Length);
311 State.Done.TrySetResult(true);
315 State.Done.TrySetResult(
true);
319 State.Done.TrySetException((Exception)e.StanzaError ??
323 }, async (Sender, e) =>
325 await (State.File?.WriteAsync(e.Data, 0, e.Data.Length) ?? Task.CompletedTask);
327 State.Done?.TrySetResult(
true);
329 }, State, Headers2.ToArray());
331 if (!await State.Done.Task)
337 if (State.StatusCode >= 200 && State.StatusCode < 300)
346 string ContentType =
string.Empty;
349 if (State.File is
null)
353 ContentType = State.HttpResponse.ContentType;
354 State.File.Position = 0;
355 Data = await State.File.ReadAllAsync();
359 State.HttpResponse, Data, ContentType));
364 State.File?.Dispose();
367 if (!(State.HttpResponse is
null))
369 await State.HttpResponse.DisposeAsync();
370 State.HttpResponse =
null;
378 internal static Exception GetExceptionObject(
int StatusCode,
string StatusMessage,
381 return StatusCode
switch
420 HTTP.NotImplementedException.Code =>
new HTTP.NotImplementedException(Data, ContentType),
423 _ =>
new HttpException(StatusCode, StatusMessage, Data, ContentType),
427 private static string[] GetMethods(
string Allow)
429 if (
string.IsNullOrEmpty(Allow))
430 return Array.Empty<
string>();
432 string[] Result = Allow.Split(
',');
433 int i, c = Result.Length;
435 for (i = 0; i < c; i++)
436 Result[i] = Result[i].Trim();
445 public TaskCompletionSource<bool> Done =
new TaskCompletionSource<bool>();
446 public string StatusMessage =
string.Empty;
447 public int StatusCode = 0;
Contains information about a response to a content request.
Contains information about a stream response to a content request.
Static class managing encoding and decoding of internet content.
static int DefaultTimeout
Default timeout of internet access methods, in milliseconds.
static Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri)
Decodes an object.
Generic exception, with meta-data for logging.
The server, while acting as a gateway or proxy, received an invalid response from the upstream server...
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
The request could not be completed due to a conflict with the current state of the resource....
The request failed due to failure of a previous request (e.g., a PROPPATCH).
The server understood the request, but is refusing to fulfill it. Authorization will not help and the...
The requested resource resides temporarily under a different URI. Since the redirection might be alte...
The server, while acting as a gateway or proxy, did not receive a timely response from the upstream s...
The requested resource is no longer available at the server and no forwarding address is known....
Base class of all HTTP Exceptions.
Base class for all HTTP fields.
Represets a response of an HTTP client request.
HttpRequest Request
Corresponding HTTP Request
string GetFirstHeader(string FieldName)
Gets the first header value matching a given header field name.
string[] GetChallenges()
Gets available WWW-Authenticate challenges returned in the response.
The server is unable to store the representation needed to complete the request.
The server encountered an unexpected condition which prevented it from fulfilling the request.
The resource that is being accessed is locked.
The server detected an infinite loop while processing the request.
The server has not found anything matching the Request-URI. No indication is given of whether the con...
The request was directed at a server that is not able to produce a response (for example because a co...
The requested resource has been assigned a new permanent URI and any future references to this resour...
The client needs to authenticate to gain network access. Intended for use by intercepting proxies use...
The resource identified by the request is only capable of generating response entities which have con...
Further extensions to the request are required for the server to fulfil it.
The server has not found anything matching the Request-URI. No indication is given of whether the con...
If the client has performed a conditional GET request and access is allowed, but the document has not...
This means that the resource is now permanently located at another URI, specified by the Location: HT...
The precondition given in one or more of the request-header fields evaluated to false when it was tes...
The origin server requires the request to be conditional. Intended to prevent "the 'lost update' prob...
A server SHOULD return a response with this status code if a request included a Range request-header ...
The client did not produce a request within the time that the server was prepared to wait....
The response to the request can be found under a different URI and SHOULD be retrieved using a GET me...
The server is currently unable to handle the request due to a temporary overloading or maintenance of...
The requested resource resides temporarily under a different URI. Since the redirection MAY be altere...
The user has sent too many requests in a given amount of time. Intended for use with rate limiting sc...
Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or ...
Defined in the internet draft "A New HTTP Status Code for Legally-restricted Resources"....
The request was well-formed but was unable to be followed due to semantic errors.
The client should switch to a different protocol such as TLS/1.0, given in the Upgrade header field.
The requested resource MUST be accessed through the proxy given by the Location field....
Transparent content negotiation for the request results in a circular reference.
Response to the HttpxProxy.GetClientAsync(Uri) method call.
string BareJid
Bare JID of entity hosting the resource.
HttpxClient HttpxClient
Corresponding HttpxClient object to use for the request..
string FullJid
Full JID of entity hosting the resource.
string LocalUrl
Local part of the URL
Task Request(string To, string Method, string LocalResource, EventHandlerAsync< HttpxResponseEventArgs > Callback, EventHandlerAsync< HttpxResponseDataEventArgs > DataCallback, object State, params HttpField[] Headers)
Performs an HTTP request.
Content Getter, retrieving content using the HTTPX URI Scheme.
async Task< ContentStreamResponse > GetTempStreamAsync(Uri Uri, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, int TimeoutMs, TemporaryStream Destination, params KeyValuePair< string, string >[] Headers)
Gets a (possibly big) resource, using a Uniform Resource Identifier (or Locator).
async Task< ContentResponse > GetAsync(Uri Uri, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Gets a resource, using a Uniform Resource Identifier (or Locator).
string[] UriSchemes
Supported URI schemes.
Task< ContentStreamResponse > GetTempStreamAsync(Uri Uri, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Gets a (possibly big) resource, using a Uniform Resource Identifier (or Locator).
Task< ContentStreamResponse > GetTempStreamAsync(Uri Uri, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, TemporaryStream Destination, params KeyValuePair< string, string >[] Headers)
Gets a (possibly big) resource, using a Uniform Resource Identifier (or Locator).
const string HttpxUriScheme
httpx
bool CanGet(Uri Uri, out Grade Grade)
If the getter is able to get a resource, given its URI.
Task< ContentStreamResponse > GetTempStreamAsync(Uri Uri, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, params KeyValuePair< string, string >[] Headers)
Gets a (possibly big) resource, using a Uniform Resource Identifier (or Locator).
Task< ContentResponse > GetAsync(Uri Uri, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, params KeyValuePair< string, string >[] Headers)
Gets a resource, using a Uniform Resource Identifier (or Locator).
HttpxGetter()
Content Getter, retrieving content using the HTTPX URI Scheme.
Implements a Proxy resource that allows Web clients to fetch HTTP-based resources over HTTPX.
Maintains information about an item in the roster.
bool HasLastPresence
If the roster item has received presence from an online resource having the given bare JID.
string LastPresenceFullJid
Full JID of last resource sending online presence.
PresenceEventArgs LastPresence
Last presence received from a resource having this bare JID.
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
bool Disposed
If the client has been disposed.
bool TryGetExtension(Type Type, out IXmppExtension Extension)
Tries to get a registered extension of a specific type from the client.
RosterItem GetRosterItem(string BareJID)
Gets a roster item.
Static class that dynamically manages types and interfaces available in the runtime environment.
static bool TryGetModuleParameter(string Name, out object Value)
Tries to get a module parameter value.
Manages a temporary stream. Contents is kept in-memory, if below a memory threshold,...
Basic interface for Internet Content getters. A class implementing this interface and having a defaul...