2using System.Collections.Generic;
4using System.Security.Cryptography.X509Certificates;
6using System.Threading.Tasks;
35 public override string[]
UriSchemes =>
new string[] { HttpxGetter.HttpxUriScheme };
76 public override async Task<KeyValuePair<byte[], string>>
PutAsync(Uri Uri,
byte[] EncodedData,
string ContentType,
78 params KeyValuePair<string, string>[] Headers)
87 if (Proxy.DefaultXmppClient.Disposed || Proxy.ServerlessMessaging.Disposed)
88 throw new InvalidOperationException(
"Service is being shut down.");
100 throw new InvalidOperationException(
"Service is being shut down.");
103 throw new InvalidOperationException(
"No HTTPX Extesion has been registered on the XMPP Client.");
107 if (
string.IsNullOrEmpty(Uri.UserInfo))
108 FullJid = BareJid = Uri.Authority;
111 BareJid = Uri.UserInfo +
"@" + Uri.Authority;
116 throw new ConflictException(
"No approved presence subscription with " + BareJid +
".");
123 LocalUrl = Uri.PathAndQuery + Uri.Fragment;
126 throw new InvalidOperationException(
"An HTTPX Proxy or XMPP Client Module Parameter has not been registered.");
128 List<HttpField> Headers2 =
new List<HttpField>();
129 bool HasContentType =
false;
130 bool HasHost =
false;
132 foreach (KeyValuePair<string, string> Header
in Headers)
134 switch (Header.Key.ToLower())
137 Headers2.Add(
new HttpField(
"Host", BareJid));
147 Headers2.Add(
new HttpField(Header.Key, Header.Value));
148 HasContentType =
true;
152 Headers2.Add(
new HttpField(Header.Key, Header.Value));
158 Headers2.Add(
new HttpField(
"Content-Type", ContentType));
161 Headers2.Add(
new HttpField(
"Host", Uri.Authority));
163 MemoryStream Data =
new MemoryStream(EncodedData);
170 Timer =
new Timer((P) =>
172 State.Done.TrySetResult(
false);
173 },
null, TimeoutMs, Timeout.Infinite);
177 await
HttpxClient.
Request(FullJid,
"PUT", LocalUrl, 1.1, Headers2, Data, async (Sender, e) =>
181 State.HttpResponse = e.HttpResponse;
182 State.StatusCode = e.StatusCode;
183 State.StatusMessage = e.StatusMessage;
187 if (State.Data is null)
188 State.Data = new MemoryStream();
190 if (!(e.Data is null))
192 await State.Data.WriteAsync(e.Data, 0, e.Data.Length);
193 State.Done.TrySetResult(true);
197 State.Done.TrySetResult(
true);
200 State.Done.TrySetException(e.StanzaError ??
new Exception(
"Unable to get resource."));
202 }, async (Sender, e) =>
204 if (State.Data is
null)
205 State.Data =
new MemoryStream();
207 await State.Data.WriteAsync(e.Data, 0, e.Data.Length);
209 State.Done.TrySetResult(
true);
213 if (!await State.Done.Task)
214 throw new TimeoutException(
"Request timed out.");
219 if (State.StatusCode >= 200 && State.StatusCode < 300)
220 return new KeyValuePair<byte[], string>(State.Data?.ToArray(), State.HttpResponse?.ContentType);
223 ContentType =
string.Empty;
224 EncodedData = State.Data?.ToArray();
226 throw HttpxGetter.GetExceptionObject(State.StatusCode, State.StatusMessage,
227 State.HttpResponse, EncodedData, ContentType);
232 State.Data?.Dispose();
235 if (!(State.HttpResponse is
null))
237 await State.HttpResponse.DisposeAsync();
238 State.HttpResponse =
null;
251 public MemoryStream Data =
null;
252 public TaskCompletionSource<bool> Done =
new TaskCompletionSource<bool>();
253 public string StatusMessage =
string.Empty;
254 public int StatusCode = 0;
Abstract base class for putters.
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< KeyValuePair< byte[], string > > PutAsync(Uri Uri, byte[] EncodedData, string ContentType, X509Certificate Certificate, RemoteCertificateEventHandler 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.
delegate void RemoteCertificateEventHandler(object Sender, RemoteCertificateEventArgs e)
Delegate for remote certificate event handlers.