Ejemplo n.º 1
0
        private MqttClientOptionsBuilder BuildConnectionOptions()
        {
            var mqttClientOptionsBuilder = new MqttClientOptionsBuilder();

            if (Uri != null && RequestHeaders != null && RequestHeaders.Any())
            {
                return(mqttClientOptionsBuilder.WithWebSocketServer(BuildWebSocketServerOptions));
            }

            return(mqttClientOptionsBuilder.WithTcpServer(BuildTcpServerOptions));
        }
        public EncodedParameters Encode()
        {
            var result = new EncodedParameters(_options, AccessToken);

            result.TimeStamp = TimeStamp.ToEpochTime();

            if (Method != null)
            {
                Logger.LogDebug("Encoding method");
                result.Method = Method;
            }

            if (Host != null)
            {
                Logger.LogDebug("Encoding host");
                result.Host = Host;
            }

            if (Path != null)
            {
                Logger.LogDebug("Encoding path");
                result.Path = Path;
            }

            if (QueryParameters != null && QueryParameters.Any())
            {
                Logger.LogDebug("Encoding query params");
                var query = new EncodingQueryParameters(_options, QueryParameters);
                result.QueryParameters = query.Encode();
            }

            if (RequestHeaders != null && RequestHeaders.Any())
            {
                Logger.LogDebug("Encoding request headers");
                var headers = new EncodingHeaderList(_options, RequestHeaders);
                result.RequestHeaders = headers.Encode();
            }

            if (Body != null)
            {
                Logger.LogDebug("Encoding body");
                result.BodyHash = CalculateBodyHash();
            }

            return(result);
        }
        private AVPlayerItem GetPlayerItem(NSUrl url)
        {
            AVAsset asset;

            if (RequestHeaders != null && RequestHeaders.Any())
            {
                var options = GetOptionsWithHeaders(RequestHeaders);

                asset = AVUrlAsset.Create(url, options);
            }
            else
            {
                asset = AVAsset.FromUrl(url);
            }

            var playerItem = AVPlayerItem.FromAsset(asset);

            return(playerItem);
        }
Ejemplo n.º 4
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;
        }
        public override string ToString()
        {
            var builder = new StringBuilder(512);

            builder.AppendLine($"{GetType().FullName}: {Message}");
            builder.AppendLine($"Request: {HttpMethod} {Uri}");

            if (RequestHeaders != null && RequestHeaders.Any())
            {
                builder.AppendLine("Request headers:");
                builder.AppendLine(String.Join(Environment.NewLine, RequestHeaders.Select(h => $"{h.Key}: [{String.Join(", ", h.Value)}]")));
            }

            if (RequestContentHeaders != null && RequestContentHeaders.Any())
            {
                builder.AppendLine("Request content headers:");
                builder.AppendLine(String.Join(Environment.NewLine, RequestContentHeaders.Select(h => $"{h.Key}: [{String.Join(", ", h.Value)}]")));
            }

            if (!String.IsNullOrEmpty(RequestContent))
            {
                builder.AppendLine("Request content:");
                if (RequestContent.Length > MaximumBodyLength)
                {
                    builder.Append(RequestContent.Substring(0, MaximumBodyLength));
                    builder.AppendLine("\u2026");
                }
                else
                {
                    builder.AppendLine(RequestContent);
                }
            }

            if (StatusCode.HasValue)
            {
                builder.AppendLine($"Status: {ReasonPhrase} ({(int)StatusCode})");
            }

            if (ResponseHeaders != null && ResponseHeaders.Any())
            {
                builder.AppendLine("Response headers:");
                builder.AppendLine(String.Join(Environment.NewLine, ResponseHeaders.Select(h => $"{h.Key}: [{String.Join(", ", h.Value)}]")));
            }

            if (ResponseContentHeaders != null && ResponseContentHeaders.Any())
            {
                builder.AppendLine("Response content headers:");
                builder.AppendLine(String.Join(Environment.NewLine, ResponseContentHeaders.Select(h => $"{h.Key}: [{String.Join(", ", h.Value)}]")));
            }

            if (!String.IsNullOrEmpty(ResponseContent))
            {
                builder.AppendLine("Response content:");

                if (ResponseContent.Length > MaximumBodyLength)
                {
                    builder.Append(ResponseContent.Substring(0, MaximumBodyLength));
                    builder.AppendLine("\u2026");
                }
                else
                {
                    builder.AppendLine(ResponseContent);
                }
            }

            if (InnerException != null)
            {
                builder.AppendLine("Inner exception:");
                builder.AppendLine(InnerException.ToString());
            }
            else
            {
                builder.AppendLine("Stack trace:");
                builder.AppendLine(StackTrace);
            }

            return(builder.ToString());
        }