private static async Task <IReadOnlyList <CloudEvent> > ToCloudEventBatchInternalAsync(HttpContent content, CloudEventFormatter formatter, IEnumerable <CloudEventAttribute>?extensionAttributes, string paramName) { Validation.CheckNotNull(formatter, nameof(formatter)); if (HasCloudEventsBatchContentType(content)) { var stream = await content.ReadAsStreamAsync().ConfigureAwait(false); return(await formatter .DecodeBatchModeMessageAsync(stream, MimeUtilities.ToContentType(content.Headers.ContentType), extensionAttributes) .ConfigureAwait(false)); } else { throw new ArgumentException("HTTP message does not represent a CloudEvents batch.", paramName); } }
/// <summary> /// Converts this HTTP request into a batch of CloudEvents. /// </summary> /// <param name="httpRequest">The HTTP request to decode. Must not be null.</param> /// <param name="formatter">The event formatter to use to process the request body. Must not be null.</param> /// <param name="extensionAttributes">The extension attributes to use when populating the CloudEvent. May be null.</param> /// <returns>The decoded CloudEvent.</returns> /// <exception cref="ArgumentException">The request does not contain a CloudEvent.</exception> public static async Task <IReadOnlyList <CloudEvent> > ToCloudEventBatchAsync( this HttpRequest httpRequest, CloudEventFormatter formatter, IEnumerable <CloudEventAttribute> extensionAttributes) { Validation.CheckNotNull(httpRequest, nameof(httpRequest)); Validation.CheckNotNull(formatter, nameof(formatter)); if (HasCloudEventsBatchContentType(httpRequest)) { var contentType = MimeUtilities.CreateContentTypeOrNull(httpRequest.ContentType); return(await formatter.DecodeBatchModeMessageAsync(httpRequest.Body, contentType, extensionAttributes).ConfigureAwait(false)); } else { throw new ArgumentException("HTTP message does not represent a CloudEvents batch.", nameof(httpRequest)); } }
private async static Task <IReadOnlyList <CloudEvent> > ToCloudEventBatchInternalAsync(HttpListenerRequest httpListenerRequest, CloudEventFormatter formatter, IEnumerable <CloudEventAttribute>?extensionAttributes, bool async) { Validation.CheckNotNull(httpListenerRequest, nameof(httpListenerRequest)); Validation.CheckNotNull(formatter, nameof(formatter)); if (HasCloudEventsBatchContentType(httpListenerRequest)) { var contentType = MimeUtilities.CreateContentTypeOrNull(httpListenerRequest.ContentType); return(async ? await formatter.DecodeBatchModeMessageAsync(httpListenerRequest.InputStream, contentType, extensionAttributes).ConfigureAwait(false) : formatter.DecodeBatchModeMessage(httpListenerRequest.InputStream, contentType, extensionAttributes)); } else { throw new ArgumentException("HTTP message does not represent a CloudEvents batch.", nameof(httpListenerRequest)); } }