Example #1
0
        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));
        }
Example #2
0
        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;
        }
Example #3
0
        public string Concat(string value, CallContext?context)
        {
            context?.ServerCallContext.ShouldNotBeNull();

            return(value + context !.ServerCallContext !.RequestHeaders.First(i => i.Key == "value").Value);
        }