4using System.Threading.Tasks;
19 public const string ContentType =
"application/x-www-form-urlencoded";
33 private static readonly
string[] contentTypes =
new string[] {
ContentType };
71 KeyValuePair<string, string>[] Fields, Uri BaseUri,
ICodecProgress Progress)
73 Dictionary<string, string> Form =
new Dictionary<string, string>();
74 Dictionary<string, ChunkedList<string>> Form2 =
null;
79 foreach (
string Parameter
in s.Split(
'&'))
81 if (
string.IsNullOrEmpty(Parameter))
84 i = Parameter.IndexOf(
'=');
88 Key = Uri.UnescapeDataString(Parameter.Substring(0, i).Replace(
"+",
" "));
89 Value = Uri.UnescapeDataString(Parameter.Substring(i + 1).Replace(
"+",
" "));
99 if (Form.ContainsKey(Key))
101 Form2 =
new Dictionary<string, ChunkedList<string>>();
103 foreach (KeyValuePair<string, string> P
in Form)
125 Dictionary<string, string[]> Form3 =
new Dictionary<string, string[]>();
128 Form3[P.Key] = P.Value.ToArray();
141 if (
string.Compare(FileExtension,
"webform",
true) == 0)
164 FileExtension =
"webform";
168 FileExtension =
string.Empty;
182 if (Object is Dictionary<string, string> &&
203 public Task<ContentResponse>
EncodeAsync(
object Object, Encoding Encoding,
206 if (Object is Dictionary<string, string> Form)
208 StringBuilder sb =
new StringBuilder();
213 foreach (KeyValuePair<string, string> Pair
in Form)
220 sb.Append(Uri.EscapeDataString(Pair.Key));
222 if (!(Pair.Value is
null))
223 sb.Append(Uri.EscapeDataString(Pair.Value));
226 if (Encoding is
null)
228 ContentType = WwwFormCodec.ContentType +
"; charset=utf-8";
229 Bin = Encoding.UTF8.GetBytes(sb.ToString());
233 ContentType = WwwFormCodec.ContentType +
"; charset=" + Encoding.WebName;
234 Bin = Encoding.GetBytes(sb.ToString());
240 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"Unable to encode object, or content type not accepted.", nameof(Object))));
Contains information about a response to a content request.
Static class managing encoding and decoding of internet content.
static bool IsAccepted(string ContentType, params string[] AcceptedContentTypes)
Checks if a given content type is acceptable.
Codec of URL encoded web forms.
Task< ContentResponse > EncodeAsync(object Object, Encoding Encoding, ICodecProgress Progress, params string[] AcceptedContentTypes)
Encodes an object.
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes an object with a given content type.
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a given object.
WwwFormCodec()
Codec of URL encoded web forms.
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri, ICodecProgress Progress)
Decodes an object.
string[] FileExtensions
Supported file extensions.
string[] ContentTypes
Supported content types.
const string ContentType
application/x-www-form-urlencoded
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
A chunked list is a linked list of chunks of objects of type T .
Static class managing binary representations of strings.
static string GetString(byte[] Data, int Offset, int Count, Encoding DefaultEncoding)
Gets a string from its binary representation, taking any Byte Order Mark (BOM) into account.
Interface for reporting progress about an encoding or decoding.
Basic interface for Internet Content decoders. A class implementing this interface and having a defau...
Basic interface for Internet Content encoders. A class implementing this interface and having a defau...