public Task <string> ConcatAsync(string value, CallContext?context) { context?.ServerCallContext.ShouldNotBeNull(); var result = value + context !.ServerCallContext !.RequestHeaders.First(i => i.Key == "value").Value; return(Task.FromResult(result)); }
private void ReadRequestBody() { if ((ProxyRequest.Method.ToUpper() != "POST" && ProxyRequest.Method.ToUpper() != "PUT")) { throw new BodyNotFoundException("Request don't have a body." + "Please verify that this request is a Http POST/PUT and request content length is greater than zero before accessing the body."); } if (RequestBody == null) { var isChunked = false; string requestContentEncoding = null; if (RequestHeaders.Any(x => x.Name.ToLower() == "content-encoding")) { requestContentEncoding = RequestHeaders.First(x => x.Name.ToLower() == "content-encoding").Value; } if (RequestHeaders.Any(x => x.Name.ToLower() == "transfer-encoding")) { var transferEncoding = RequestHeaders.First(x => x.Name.ToLower() == "transfer-encoding").Value.ToLower(); if (transferEncoding.Contains("chunked")) { isChunked = true; } } if (requestContentEncoding == null && !isChunked) { RequestBody = ClientStreamReader.ReadBytes(RequestContentLength); } else { using (var requestBodyStream = new MemoryStream()) { if (isChunked) { while (true) { var chuchkHead = ClientStreamReader.ReadLine(); var chunkSize = int.Parse(chuchkHead, NumberStyles.HexNumber); if (chunkSize != 0) { var buffer = ClientStreamReader.ReadBytes(chunkSize); requestBodyStream.Write(buffer, 0, buffer.Length); //chunk trail ClientStreamReader.ReadLine(); } else { ClientStreamReader.ReadLine(); break; } } } try { switch (requestContentEncoding) { case "gzip": RequestBody = CompressionHelper.DecompressGzip(requestBodyStream); break; case "deflate": RequestBody = CompressionHelper.DecompressDeflate(requestBodyStream); break; case "zlib": RequestBody = CompressionHelper.DecompressGzip(requestBodyStream); break; default: RequestBody = requestBodyStream.ToArray(); break; } } catch { RequestBody = requestBodyStream.ToArray(); } } } } RequestBodyRead = true; }
public string Concat(string value, CallContext?context) { context?.ServerCallContext.ShouldNotBeNull(); return(value + context !.ServerCallContext !.RequestHeaders.First(i => i.Key == "value").Value); }