This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class FileContent : HttpContent | |
| { | |
| private const int DefaultBufferSize = 1024 * 64; | |
| private readonly string _fileName; | |
| private readonly FileInfo _fileInfo; | |
| public FileContent(string fileName, MediaTypeHeaderValue contentType = null) | |
| { | |
| Headers.ContentType = contentType ?? new MediaTypeHeaderValue("application/octet-stream"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ImageContent : HttpContent | |
| { | |
| private Image _image; | |
| public ImageContent(Image image, MediaTypeHeaderValue mediatype) | |
| { | |
| _image = image; | |
| Headers.ContentType = mediatype; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class TokenValidationHandler : DelegatingHandler | |
| { | |
| protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | |
| { | |
| const string errorMessage = "Unauthorized access"; | |
| const HttpStatusCode code = HttpStatusCode.Unauthorized; | |
| var authValue = request.Headers.Authorization; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class CollectionJsonContent : HttpContent | |
| { | |
| private readonly ReadDocument _readDocument; | |
| private readonly JsonSerializer _serializer; | |
| public CollectionJsonContent(Collection collection) | |
| { | |
| _serializer = JsonSerializer.Create(new JsonSerializerSettings | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| +using System; | |
| +using System.Collections.Generic; | |
| +using System.Linq; | |
| +using System.Text; | |
| +using System.Web.Http; | |
| +using WebApiContrib.CollectionJson; | |
| +using WebApiContrib.Formatting.CollectionJson; | |
| +using WebApiContrib.Formatting.CollectionJson.Infrastructure; | |
| +using WebApiContrib.Formatting.CollectionJson.Models; | |
| + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| +using System; | |
| +using System.Collections.Generic; | |
| +using System.Web.Http; | |
| +using WebApiContrib.CollectionJson; | |
| +using WebApiContrib.Formatting.CollectionJson; | |
| +using WebApiContrib.Formatting.CollectionJson.Infrastructure; | |
| +using WebApiContrib.Formatting.CollectionJson.Models; | |
| + | |
| +namespace CollectionJson.Controllers | |
| +{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class CollectionJsonContent : HttpContent | |
| { | |
| private readonly ReadDocument _readDocument; | |
| private readonly JsonSerializer _serializer; | |
| public CollectionJsonContent(Collection collection) | |
| { | |
| _serializer = JsonSerializer.Create(new JsonSerializerSettings | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Fact] | |
| public void DoesNotPreserveHttpHeaderValueOrderOrCase() | |
| { | |
| var response = new HttpResponseMessage(); | |
| string input = "Private, max-age=60, s-maxage=60"; | |
| response.Headers.TryAddWithoutValidation("Cache-Control", input); | |
| var header = response.Headers.First(); | |
| var output = string.Join(",", header.Value); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ConsoleRequestLogger : DelegatingHandler | |
| { | |
| protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | |
| { | |
| Console.ForegroundColor = ConsoleColor.Cyan; | |
| Console.WriteLine("> {0} {1}",request.Method,request.RequestUri.GetComponents(UriComponents.PathAndQuery, UriFormat.SafeUnescaped)); | |
| ProcessHeader(request.Headers, (name, value) => Console.WriteLine("> {0}: {1}", name, value)); | |
| if (request.Content != null) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class HtmlFormatter : OutputFormatter | |
| { | |
| public HtmlFormatter() | |
| { | |
| SupportedEncodings.Add(Encodings.UTF8EncodingWithoutBOM); // Whatever this should be | |
| SupportedEncodings.Add(Encodings.UTF16EncodingLittleEndian); // Whatever this should be | |
| SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("text/html")); | |
| } | |
| public override bool CanWriteResult(OutputFormatterContext context, MediaTypeHeaderValue contentType) |