|
@@ -1,4 +1,7 @@
|
|
|
using System;
|
|
|
+using System.IO;
|
|
|
+using System.Collections.Generic;
|
|
|
+using Google.ProtocolBuffers.Collections;
|
|
|
|
|
|
namespace Google.ProtocolBuffers.Serialization.Http
|
|
|
{
|
|
@@ -22,10 +25,92 @@ namespace Google.ProtocolBuffers.Serialization.Http
|
|
|
/// </remarks>
|
|
|
public const string ContentTypeJson = "application/json";
|
|
|
|
|
|
+ /// <summary>The mime type for query strings and x-www-form-urlencoded content</summary>
|
|
|
+ /// <remarks>This mime type is input-only</remarks>
|
|
|
+ public const string ContentFormUrlEncoded = "application/x-www-form-urlencoded";
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Default mime-type handling for input
|
|
|
+ /// </summary>
|
|
|
+ private static readonly IDictionary<string, Converter<Stream, ICodedInputStream>> MimeInputDefaults =
|
|
|
+ new ReadOnlyDictionary<string, Converter<Stream, ICodedInputStream>>(
|
|
|
+ new Dictionary<string, Converter<Stream, ICodedInputStream>>(StringComparer.OrdinalIgnoreCase)
|
|
|
+ {
|
|
|
+ {"application/json", JsonFormatReader.CreateInstance},
|
|
|
+ {"application/x-json", JsonFormatReader.CreateInstance},
|
|
|
+ {"application/x-javascript", JsonFormatReader.CreateInstance},
|
|
|
+ {"text/javascript", JsonFormatReader.CreateInstance},
|
|
|
+ {"text/x-javascript", JsonFormatReader.CreateInstance},
|
|
|
+ {"text/x-json", JsonFormatReader.CreateInstance},
|
|
|
+ {"text/json", JsonFormatReader.CreateInstance},
|
|
|
+ {"text/xml", XmlFormatReader.CreateInstance},
|
|
|
+ {"application/xml", XmlFormatReader.CreateInstance},
|
|
|
+ {"application/binary", CodedInputStream.CreateInstance},
|
|
|
+ {"application/x-protobuf", CodedInputStream.CreateInstance},
|
|
|
+ {"application/vnd.google.protobuf", CodedInputStream.CreateInstance},
|
|
|
+ {"application/x-www-form-urlencoded", FormUrlEncodedReader.CreateInstance},
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Default mime-type handling for output
|
|
|
+ /// </summary>
|
|
|
+ private static readonly IDictionary<string, Converter<Stream, ICodedOutputStream>> MimeOutputDefaults =
|
|
|
+ new ReadOnlyDictionary<string, Converter<Stream, ICodedOutputStream>>(
|
|
|
+ new Dictionary<string, Converter<Stream, ICodedOutputStream>>(StringComparer.OrdinalIgnoreCase)
|
|
|
+ {
|
|
|
+ {"application/json", JsonFormatWriter.CreateInstance},
|
|
|
+ {"application/x-json", JsonFormatWriter.CreateInstance},
|
|
|
+ {"application/x-javascript", JsonFormatWriter.CreateInstance},
|
|
|
+ {"text/javascript", JsonFormatWriter.CreateInstance},
|
|
|
+ {"text/x-javascript", JsonFormatWriter.CreateInstance},
|
|
|
+ {"text/x-json", JsonFormatWriter.CreateInstance},
|
|
|
+ {"text/json", JsonFormatWriter.CreateInstance},
|
|
|
+ {"text/xml", XmlFormatWriter.CreateInstance},
|
|
|
+ {"application/xml", XmlFormatWriter.CreateInstance},
|
|
|
+ {"application/binary", CodedOutputStream.CreateInstance},
|
|
|
+ {"application/x-protobuf", CodedOutputStream.CreateInstance},
|
|
|
+ {"application/vnd.google.protobuf", CodedOutputStream.CreateInstance},
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private string _defaultContentType;
|
|
|
private string _xmlReaderRootElementName;
|
|
|
private string _xmlWriterRootElementName;
|
|
|
private ExtensionRegistry _extensionRegistry;
|
|
|
+ private Dictionary<string, Converter<Stream, ICodedInputStream>> _mimeInputTypes;
|
|
|
+ private Dictionary<string, Converter<Stream, ICodedOutputStream>> _mimeOutputTypes;
|
|
|
+
|
|
|
+ /// <summary> Provides access to modify the mime-type input stream construction </summary>
|
|
|
+ public IDictionary<string, Converter<Stream, ICodedInputStream>> MimeInputTypes
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ return _mimeInputTypes ??
|
|
|
+ (_mimeInputTypes = new Dictionary<string, Converter<Stream, ICodedInputStream>>(
|
|
|
+ MimeInputDefaults, StringComparer.OrdinalIgnoreCase));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary> Provides access to modify the mime-type input stream construction </summary>
|
|
|
+ public IDictionary<string, Converter<Stream, ICodedOutputStream>> MimeOutputTypes
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ return _mimeOutputTypes ??
|
|
|
+ (_mimeOutputTypes = new Dictionary<string, Converter<Stream, ICodedOutputStream>>(
|
|
|
+ MimeOutputDefaults, StringComparer.OrdinalIgnoreCase));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ internal IDictionary<string, Converter<Stream, ICodedInputStream>> MimeInputTypesReadOnly
|
|
|
+ { get { return _mimeInputTypes ?? MimeInputDefaults; } }
|
|
|
+
|
|
|
+ internal IDictionary<string, Converter<Stream, ICodedOutputStream>> MimeOutputTypesReadOnly
|
|
|
+ { get { return _mimeOutputTypes ?? MimeOutputDefaults; } }
|
|
|
|
|
|
/// <summary>
|
|
|
/// The default content type to use if the input type is null or empty. If this
|