public async Task UnsupportedContentType()
 {
     await GetApiInfoInvalidResponse(
         _ => new HttpResponseMessage(HttpStatusCode.OK)
     {
         Content = new StringContent("text", Encoding.UTF8, "text/plain")
     },
         ServiceErrors.InvalidResponse, HttpServiceErrors.CreateUnsupportedContentType("text/plain").Message);
 }
Exemplo n.º 2
0
    /// <summary>
    /// Reads an object from the specified HTTP content.
    /// </summary>
    public async Task <ServiceResult <object> > ReadHttpContentAsync(Type objectType, HttpContent?content, CancellationToken cancellationToken = default)
    {
        var contentType = content?.Headers.ContentType;

        if (contentType == null)
        {
            return(ServiceResult.Failure(HttpServiceErrors.CreateMissingContentType()));
        }

        var mediaType = contentType.MediaType ?? "";

        if (!IsSupportedMediaType(mediaType))
        {
            return(ServiceResult.Failure(HttpServiceErrors.CreateUnsupportedContentType(mediaType)));
        }

        return(await ReadHttpContentAsyncCore(objectType, content !, cancellationToken).ConfigureAwait(false));
    }