public async Task <CloudMessage> Create(HttpRequest httpRequest) { if (httpRequest is null) { throw new ArgumentNullException(nameof(httpRequest)); } var cloudMessageContent = new HttpRequestCloudMessageContent { Method = httpRequest.Method, Uri = httpRequest.Path + httpRequest.QueryString, Content = await LoadHttpRequestContent(httpRequest).ConfigureAwait(false) }; if (!string.IsNullOrEmpty(httpRequest.ContentType)) { cloudMessageContent.Headers = new Dictionary <string, string> { ["Content-Type"] = httpRequest.ContentType }; } var requestMessage = new CloudMessage { Type = CloudMessageType.HttpInvoke, Payload = _cloudMessageSerializer.Pack(cloudMessageContent) }; return(requestMessage); }
public async Task <CloudMessage> Create(HttpRequest httpRequest) { if (httpRequest is null) { throw new ArgumentNullException(nameof(httpRequest)); } var contentLength = (int)(httpRequest.ContentLength ?? 0L); var requestContentBuffer = ArrayPool <byte> .Shared.Rent(contentLength); try { var cloudMessageContent = new HttpRequestCloudMessageContent { Method = httpRequest.Method, Uri = httpRequest.Path + httpRequest.QueryString }; if (contentLength > 0) { await httpRequest.Body.ReadAsync(requestContentBuffer, 0, contentLength).ConfigureAwait(false); cloudMessageContent.Content = new ArraySegment <byte>(requestContentBuffer, 0, contentLength); } if (!string.IsNullOrEmpty(httpRequest.ContentType)) { cloudMessageContent.Headers = new Dictionary <string, string> { ["Content-Type"] = httpRequest.ContentType }; } var requestMessage = new CloudMessage { Type = CloudMessageType.HttpInvoke, Payload = _cloudMessageSerializer.Pack(cloudMessageContent) }; return(requestMessage); } finally { ArrayPool <byte> .Shared.Return(requestContentBuffer); } }