private static string ReadContentAsync(HttpContent content) { Task task = content.LoadIntoBufferAsync(); task.Wait(TimeoutConstant.DefaultTimeout); Assert.Equal(TaskStatus.RanToCompletion, task.Status); return content.ReadAsStringAsync().Result; }
private static string ReadContentAsync(HttpContent content) { Task task = content.LoadIntoBufferAsync(); task.Wait(TimeoutConstant.DefaultTimeout); Assert.Equal(TaskStatus.RanToCompletion, task.Status); return(content.ReadAsStringAsync().Result); }
private static async Task BufferRequestBodyAsync(IOwinRequest owinRequest, HttpContent content) { await content.LoadIntoBufferAsync(); // We need to replace the request body with a buffered stream so that other // components can read the stream owinRequest.Body = await content.ReadAsStreamAsync(); }
private static async Task <string> ReadContentAsync(HttpContent content) { await content.LoadIntoBufferAsync(); return(await content.ReadAsStringAsync()); }
private void PrepareAndStartContentUpload(RequestState state) { HttpContent requestContent = state.requestMessage.Content; Contract.Assert(requestContent != null); try { // Determine how to communicate the length of the request content. if (state.requestMessage.Headers.TransferEncodingChunked == true) { state.webRequest.SendChunked = true; StartGettingRequestStream(state); } else { long?contentLength = requestContent.Headers.ContentLength; if (contentLength != null) { state.webRequest.ContentLength = (long)contentLength; StartGettingRequestStream(state); } else { // If we don't have a content length and we don't use chunked, then we must buffer the content. // If the user specified a zero buffer size, we throw. if (_maxRequestContentBufferSize == 0) { throw new HttpRequestException(SR.net_http_handler_nocontentlength); } // HttpContent couldn't calculate the content length. Chunked is not specified. Buffer the // content to get the content length. requestContent.LoadIntoBufferAsync(_maxRequestContentBufferSize).ContinueWithStandard(task => { if (task.IsFaulted) { HandleAsyncException(state, task.Exception.GetBaseException()); return; } try { contentLength = requestContent.Headers.ContentLength; Contract.Assert(contentLength != null, "After buffering content, ContentLength must not be null."); state.webRequest.ContentLength = (long)contentLength; StartGettingRequestStream(state); } catch (Exception e) { HandleAsyncException(state, e); } }); } } } catch (Exception e) { HandleAsyncException(state, e); } }
/// <summary> /// Serialize the HTTP content to a memory buffer as a synchronous operation. /// </summary> /// <param name="maxBufferSize">The maximum size, in bytes, of the buffer to use.</param> public static void LoadIntoBuffer(this HttpContent content, long maxBufferSize) { Task.Run(() => content.LoadIntoBufferAsync(maxBufferSize)).Wait(); }
/// <summary> /// Serialize the HTTP content to a memory buffer as a synchronous operation. /// </summary> public static void LoadIntoBuffer(this HttpContent content) { Task.Run(() => content.LoadIntoBufferAsync()).Wait(); }
private static async Task WriteContentHeadersAndBody(StringWriter sw, HttpContent content) { if (content != null) { await content.LoadIntoBufferAsync(); WriteHeaders(sw, content.Headers); sw.WriteLine(); sw.Write(await content.ReadAsStringAsync()); sw.WriteLine(); } else sw.WriteLine(); }
private static async Task BufferRequestBodyAsync(IDictionary<string, object> environment, HttpContent content) { await content.LoadIntoBufferAsync(); // We need to replace the request body with a buffered stream so that other // components can read the stream environment[OwinConstants.RequestBodyKey] = await content.ReadAsStreamAsync(); }