4using System.Security.Cryptography.X509Certificates;
6using System.Threading.Tasks;
36 public override string[]
UriSchemes =>
new string[] { HttpxGetter.HttpxUriScheme };
78 public override async Task<ContentBinaryResponse>
PutAsync(Uri Uri,
byte[] EncodedData,
string ContentType,
79 X509Certificate Certificate, EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
int TimeoutMs,
80 params KeyValuePair<string, string>[] Headers)
89 if (Proxy.DefaultXmppClient.Disposed || Proxy.ServerlessMessaging.Disposed)
105 return new ContentBinaryResponse(
new InvalidOperationException(
"No HTTPX Extesion has been registered on the XMPP Client."));
109 if (
string.IsNullOrEmpty(Uri.UserInfo))
110 FullJid = BareJid = Uri.Authority;
113 BareJid = Uri.UserInfo +
"@" + Uri.Authority;
125 LocalUrl = Uri.PathAndQuery + Uri.Fragment;
128 return new ContentBinaryResponse(
new InvalidOperationException(
"An HTTPX Proxy or XMPP Client Module Parameter has not been registered."));
130 List<HttpField> Headers2 =
new List<HttpField>();
131 bool HasContentType =
false;
132 bool HasHost =
false;
134 foreach (KeyValuePair<string, string> Header
in Headers)
136 switch (Header.Key.ToLower())
139 Headers2.Add(
new HttpField(
"Host", BareJid));
149 Headers2.Add(
new HttpField(Header.Key, Header.Value));
150 HasContentType =
true;
154 Headers2.Add(
new HttpField(Header.Key, Header.Value));
160 Headers2.Add(
new HttpField(
"Content-Type", ContentType));
163 Headers2.Add(
new HttpField(
"Host", Uri.Authority));
165 MemoryStream Data =
new MemoryStream(EncodedData);
172 Timer =
new Timer((P) =>
174 State.Done.TrySetResult(
false);
175 },
null, TimeoutMs, Timeout.Infinite);
179 await
HttpxClient.
Request(FullJid,
"PUT", LocalUrl, 1.1, Headers2, Data, async (Sender, e) =>
183 State.HttpResponse = e.HttpResponse;
184 State.StatusCode = e.StatusCode;
185 State.StatusMessage = e.StatusMessage;
189 State.Data ??= new MemoryStream();
191 if (!(e.Data is null))
193 await State.Data.WriteAsync(e.Data, 0, e.Data.Length);
194 State.Done.TrySetResult(true);
198 State.Done.TrySetResult(
true);
202 State.Done.TrySetException((Exception)e.StanzaError ??
206 }, async (Sender, e) =>
208 State.Data ??=
new MemoryStream();
210 await State.Data.WriteAsync(e.Data, 0, e.Data.Length);
212 State.Done.TrySetResult(
true);
216 if (!await State.Done.Task)
222 if (State.StatusCode >= 200 && State.StatusCode < 300)
226 ContentType =
string.Empty;
227 EncodedData = State.Data?.ToArray();
230 State.HttpResponse, EncodedData, ContentType));
235 State.Data?.Dispose();
238 if (!(State.HttpResponse is
null))
240 await State.HttpResponse.DisposeAsync();
241 State.HttpResponse =
null;
254 public MemoryStream Data =
null;
255 public TaskCompletionSource<bool> Done =
new TaskCompletionSource<bool>();
256 public string StatusMessage =
string.Empty;
257 public int StatusCode = 0;
Contains information about a binary response to a content request.
Abstract base class for putters.
Generic exception, with meta-data for logging.
The request could not be completed due to a conflict with the current state of the resource....
Base class for all HTTP fields.
Represets a response of an HTTP client request.
The server is currently unable to handle the request due to a temporary overloading or maintenance of...
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.
const string HttpxUriScheme
httpx
Implements a Proxy resource that allows Web clients to fetch HTTP-based resources over HTTPX.
Content Putter, puting content using the HTTPX URI Scheme.
HttpxPutter()
Content Putter, puting content using the HTTPX URI Scheme.
override async Task< ContentBinaryResponse > PutAsync(Uri Uri, byte[] EncodedData, string ContentType, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Puts to a resource, using a Uniform Resource Identifier (or Locator).
override bool CanPut(Uri Uri, out Grade Grade)
If the putter is able to put to a resource, given its URI.
override string[] UriSchemes
Supported URI schemes.
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.