diff options
author | 杨宇千 <crupest@outlook.com> | 2019-10-31 15:02:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-31 15:02:03 +0800 |
commit | 2de7fa95bb5ad0a10f74fb390bac464a250dee42 (patch) | |
tree | ba42530cf4f13621a7a3a7ff661e383117119883 /Timeline/Formatters | |
parent | f08f53d6fcd9baf9dd3b95209f7c7448ae8168d4 (diff) | |
parent | cf2055f956695bc0b9ecdb6d8023d0d199b98462 (diff) | |
download | timeline-2de7fa95bb5ad0a10f74fb390bac464a250dee42.tar.gz timeline-2de7fa95bb5ad0a10f74fb390bac464a250dee42.tar.bz2 timeline-2de7fa95bb5ad0a10f74fb390bac464a250dee42.zip |
Merge pull request #53 from crupest/nickname
Add nickname support.
Diffstat (limited to 'Timeline/Formatters')
-rw-r--r-- | Timeline/Formatters/StringInputFormatter.cs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Timeline/Formatters/StringInputFormatter.cs b/Timeline/Formatters/StringInputFormatter.cs new file mode 100644 index 00000000..90847e36 --- /dev/null +++ b/Timeline/Formatters/StringInputFormatter.cs @@ -0,0 +1,27 @@ +using Microsoft.AspNetCore.Mvc.Formatters;
+using Microsoft.Net.Http.Headers;
+using System.IO;
+using System.Net.Mime;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Timeline.Formatters
+{
+ public class StringInputFormatter : TextInputFormatter
+ {
+ public StringInputFormatter()
+ {
+ SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse(MediaTypeNames.Text.Plain));
+ SupportedEncodings.Add(Encoding.UTF8);
+ }
+
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods")]
+ public override async Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context, Encoding effectiveEncoding)
+ {
+ var request = context.HttpContext.Request;
+ using var reader = new StreamReader(request.Body, effectiveEncoding);
+ var stringContent = await reader.ReadToEndAsync();
+ return await InputFormatterResult.SuccessAsync(stringContent);
+ }
+ }
+}
|