Exemplo n.º 1
0
        public override Task ApplyArgument(HttpApiRequest request, string name, object argument)
        {
            var value = TypeConverter.ConvertTo<string>(TypeConversionContext.Path, argument);
            request.Url.Path[name] = value;

            return base.ApplyArgument(request, name, argument);
        }
        public override Task ApplyArgument(HttpApiRequest request, string name, object argument)
        {
            if (request.Body == null)
            {
                request.Body = new JsonHttpBody(new JObject());
            }
            else
            {
                if (!(request.Body is JsonHttpBody))
                {
                    throw new Exception("ComposedJsonArgumentHandler expects either a null body or a JsonHttpBody");
                }
                else if (!(((JsonHttpBody)request.Body).Json is JObject))
                {
                    throw new Exception("ComposedJsonArgumentHandler expects a JsonHttpBody with a JObject value");
                }
            }

            var jsonName   = Name ?? name;
            var jsonObject = (JObject)((JsonHttpBody)request.Body).Json;
            var value      = TypeConverter.ConvertTo <JToken>(TypeConversionContext.Body, argument);

            jsonObject[jsonName] = value;

            return(base.ApplyArgument(request, name, argument));
        }
Exemplo n.º 3
0
 protected override Task<object> ProvideResult(HttpApiRequest request, HttpApiResponse response)
 {
     // Use JSON.NET to do the deserialization
     var form = (FormHttpBody)response.Body;
     var json = JToken.FromObject(form.Values);
     return Task.FromResult(json.ToObject(ResponseType));
 }
Exemplo n.º 4
0
        public async Task <HttpHandlerResponse> Call(HttpApiRequest request)
        {
            using (var client = new HttpClient(handler()))
            {
                try
                {
                    var requestWriteTime = new Stopwatch();
                    requestWriteTime.Start();

                    var response = await client.SendAsync(CreateRequestMessage(request));

                    requestWriteTime.Stop();

                    var responseReadTime = new Stopwatch();
                    responseReadTime.Start();
                    var result = await CreateResponse(request, response);

                    responseReadTime.Stop();

                    return(new HttpHandlerResponse(result, requestWriteTime.Elapsed, responseReadTime.Elapsed));
                }
                catch (HttpRequestException e) when(IsProxyRequiredException(e, out var response))
                {
                    return(new HttpHandlerResponse(response, TimeSpan.Zero, TimeSpan.Zero));
                }
                catch (Exception e)
                {
                    throw new Exception($"Error making {request.Method} request to {request.Url}", e);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Function for login fase used by Enterkey event and Login butten event
        /// </summary>
        private void login()
        {
            if (string.IsNullOrEmpty(tb_mail.Text) || string.IsNullOrEmpty(pb_password.Password) || string.IsNullOrEmpty(tb_mail.Text) && string.IsNullOrEmpty(pb_password.Password))
            {
                MessageBox.Show("Please fill out username and password");
            }
            else
            {
                if (tb_password.Visibility == Visibility.Visible)
                {
                    pb_password.Password = tb_password.Text;
                }

                string JSONapikey = HttpApiRequest.ClimateLogin(tb_mail.Text, pb_password.Password);
                if (string.IsNullOrEmpty(JSONapikey))
                {
                    MessageBox.Show("Wrong username or password");
                }
                else
                {
                    UserInformation.ApiKey   = JsonDataConverter.deserializedApikey(JSONapikey);
                    UserInformation.Mail     = tb_mail.Text;
                    UserInformation.Password = pb_password.Password;

                    Climate c = new Climate();
                    c.Show();
                    Close();
                }
            }
        }
Exemplo n.º 6
0
        protected override async Task <object> ProvideResult(HttpApiRequest request, HttpApiResponse response)
        {
            var body      = response.Body;
            var byteArray = await body.AcceptAsync(new ByteArrayExtractor());

            return(byteArray);
        }
Exemplo n.º 7
0
        public void GetParametersAsQueryStringParameteIsNotNullTest()
        {
            //arrange
            var mockHeader       = new Mock <IHttpRequestHeader>();
            var mockApiParameter = new Mock <List <IApiParameter> >();
            var mockHeader1      = Mock.Of <IApiParameter>();

            mockHeader1.Name  = "q";
            mockHeader1.Value = "#test";
            var mockHeader2 = Mock.Of <IApiParameter>();

            mockHeader2.Name  = "count";
            mockHeader2.Value = "100";
            var mockHeaderList = new List <IApiParameter>();

            mockHeaderList.Add(mockHeader1);
            mockHeaderList.Add(mockHeader2);
            var httpApiRequest = new HttpApiRequest <string>(Enums.APIsListEnum.SearchForTweets, mockHeaderList, mockHeader.Object);

            //act
            var    result   = httpApiRequest.GetParametersAsQueryString();
            string expected = "q=%23test&count=100";

            Assert.AreEqual(result, expected);
        }
        public override Task ApplyArgument(HttpApiRequest request, string name, object argument)
        {
            var requestHandler = (Action<HttpApiRequest>)argument;
            requestHandler(request);

            return base.ApplyArgument(request, name, argument);
        }
        public override Task ApplyArgument(HttpApiRequest request, string name, object argument)
        {
            var requestHandler = (Action <HttpApiRequest>)argument;

            requestHandler(request);

            return(base.ApplyArgument(request, name, argument));
        }
Exemplo n.º 10
0
        protected override Task <object> ProvideResult(HttpApiRequest request, HttpApiResponse response)
        {
            // Use JSON.NET to do the deserialization
            var form = (FormHttpBody)response.Body;
            var json = JToken.FromObject(form.Values);

            return(Task.FromResult(json.ToObject(ResponseType)));
        }
Exemplo n.º 11
0
        public override Task ApplyArgument(HttpApiRequest request, string name, object argument)
        {
            var value = TypeConverter.ConvertTo <string>(TypeConversionContext.Path, argument);

            request.Url.Path[name] = value;

            return(base.ApplyArgument(request, name, argument));
        }
Exemplo n.º 12
0
        public override Task ApplyArgument(HttpApiRequest request, string name, object argument)
        {
            name = Name ?? name;

            var values = Values ?? TypeConverter.ConvertTo<string[]>(TypeConversionContext.Header, argument);

            request.Headers.Add(new HttpHeader(name, values));
            return base.ApplyArgument(request, name, argument);
        }
Exemplo n.º 13
0
        public override Task ApplyArgument(HttpApiRequest request, string name, object argument)
        {
            name = Name ?? name;

            var values = Values ?? TypeConverter.ConvertTo <string[]>(TypeConversionContext.Header, argument);

            request.Headers.Add(new HttpHeader(name, values));
            return(base.ApplyArgument(request, name, argument));
        }
Exemplo n.º 14
0
        protected override Task<object> ProvideResult(HttpApiRequest request, HttpApiResponse response)
        {
            var jsonBody = response.Body as JsonHttpBody;
            if (jsonBody == null)
                throw new Exception("Expected a JsonHttpBody in the response");

            var result = TypeConverter.ConvertTo(TypeConversionContext.Body, ResponseType, jsonBody.Json);
            return Task.FromResult(result);
        }
Exemplo n.º 15
0
        public override Task ApplyArgument(HttpApiRequest request, string name, object argument)
        {
            if (request.Body != null)
                throw new Exception("DirectJsonArgumentHandler expects a null request body.");

            var token = TypeConverter.ConvertTo<JToken>(TypeConversionContext.Body, argument);
            request.Body = new JsonHttpBody(token);

            return base.ApplyArgument(request, name, argument);
        }
        public override Task ApplyArgument(HttpApiRequest request, string name, object argument)
        {
            if (request.ResponseContentTypeOverride != null)
            {
                throw new Exception("The response content type has already been overridden.");
            }

            request.ResponseContentTypeOverride = "application/octet-stream";

            return(base.ApplyArgument(request, name, argument));
        }
Exemplo n.º 17
0
        public void GetParametersAsQueryStringParameteIsNullTest()
        {
            //arrange
            var mockHeader     = new Mock <IHttpRequestHeader>();
            var httpApiRequest = new HttpApiRequest <string>(Enums.APIsListEnum.SearchForTweets, mockHeader.Object);

            //act
            var    actual   = httpApiRequest.GetParametersAsQueryString();
            string expected = null;

            Assert.AreEqual(actual, expected);
        }
Exemplo n.º 18
0
        public override Task ApplyArgument(HttpApiRequest request, string name, object argument)
        {
            if (request.Body != null)
                throw new Exception("Can only use StreamArgumentHandler for one argument.  If you need multiple arguments, you " +
                                    "should be using MultipartStreamArgumentHandler, which ought to have been selected " +
                                    "automatically under default conditions.");

            var streamBody = new StreamHttpBody((Stream)argument);
            request.Body = streamBody;

            return base.ApplyArgument(request, name, argument);
        }
Exemplo n.º 19
0
        public override Task ApplyArgument(HttpApiRequest request, string name, object argument)
        {
            if (request.Body != null)
            {
                throw new Exception("DirectJsonArgumentHandler expects a null request body.");
            }

            var token = TypeConverter.ConvertTo <JToken>(TypeConversionContext.Body, argument);

            request.Body = new JsonHttpBody(token);

            return(base.ApplyArgument(request, name, argument));
        }
Exemplo n.º 20
0
        public override Task ApplyArgument(HttpApiRequest request, string name, object argument)
        {
            if (request.Body == null)
                request.Body = new FormHttpBody();
            else if (!(request.Body is FormHttpBody))
                throw new Exception("Cannot apply form argument because body is already assigned and is not an instance of FormHttpBody");

            var form = (FormHttpBody)request.Body;
            var value = TypeConverter.ConvertTo<string>(TypeConversionContext.Body, argument);
            form.Values[Name ?? name] = value;

            return base.ApplyArgument(request, name, argument);
        }
Exemplo n.º 21
0
        protected override Task <object> ProvideResult(HttpApiRequest request, HttpApiResponse response)
        {
            var jsonBody = response.Body as JsonHttpBody;

            if (jsonBody == null)
            {
                throw new Exception("Expected a JsonHttpBody in the response");
            }

            var result = TypeConverter.ConvertTo(TypeConversionContext.Body, ResponseType, jsonBody.Json);

            return(Task.FromResult(result));
        }
Exemplo n.º 22
0
        public async Task<HttpApiResponse> InstrumentCall(HttpApiRequest request, Func<HttpApiRequest, Task<HttpApiResponse>> inner)
        {
            if (instrumenters.Length == 0)
                return await inner(request);

            var current = inner;
            foreach (var instrumenter in instrumenters.Skip(1).Reverse())
            {
                current = apiRequest => instrumenter(apiRequest, current);
            }

            return await instrumenters.First()(request, current);
        }
 protected override Task<object> ProvideResult(HttpApiRequest request, HttpApiResponse response)
 {
     var contentType = response.Headers.SingleOrDefault(x => x.Name == "Content-Type")?.Values?.Single();
     contentType = contentType ?? "application/json";
     switch (contentType)
     {
         case "application/x-www-form-urlencoded":
             return formHandler.HandleResponse(request, response);
         case "text/plain":
             return stringHandler.HandleResponse(request, response);
         default:
             return jsonHandler.HandleResponse(request, response);
     }
 }
Exemplo n.º 24
0
        public override Task ApplyArgument(HttpApiRequest request, string name, object argument)
        {
            if (request.Body == null)
            {
                request.Body = new MultipartHttpBody();
            }
            var multipart = (MultipartHttpBody)request.Body;
            var body = TypeConverter.ConvertTo<HttpBody>(TypeConversionContext.Body, argument);
            if (body == null)
                throw new Exception($"Could not create body for {name}");
            multipart.Data[name] = new MultipartData { Body = body };

            return base.ApplyArgument(request, name, argument);
        }
Exemplo n.º 25
0
        public override Task ApplyArgument(HttpApiRequest request, string name, object argument)
        {
            if (request.Body != null)
            {
                throw new Exception("Can only use StreamArgumentHandler for one argument.  If you need multiple arguments, you " +
                                    "should be using MultipartStreamArgumentHandler, which ought to have been selected " +
                                    "automatically under default conditions.");
            }

            var streamBody = new StreamHttpBody((Stream)argument);

            request.Body = streamBody;

            return(base.ApplyArgument(request, name, argument));
        }
Exemplo n.º 26
0
        protected override Task <object> ProvideResult(HttpApiRequest request, HttpApiResponse response)
        {
            switch (response.Body)
            {
            case JsonHttpBody _:
                return(jsonHandler.HandleResponse(request, response));

            case StringHttpBody _:
                return(stringHandler.HandleResponse(request, response));

            case FormHttpBody _:
                return(formHandler.HandleResponse(request, response));

            default:
                return(Task.FromResult <object>(null));
            }
        }
Exemplo n.º 27
0
        public override Task ApplyArgument(HttpApiRequest request, string name, object argument)
        {
            if (request.Body == null)
            {
                request.Body = new FormHttpBody();
            }
            else if (!(request.Body is FormHttpBody))
            {
                throw new Exception("Cannot apply form argument because body is already assigned and is not an instance of FormHttpBody");
            }

            var form  = (FormHttpBody)request.Body;
            var value = TypeConverter.ConvertTo <string>(TypeConversionContext.Body, argument);

            form.Values[Name ?? name] = value;

            return(base.ApplyArgument(request, name, argument));
        }
Exemplo n.º 28
0
        public void HttpApiRequest_ClimateLogin()
        {
            string mail     = "test";
            string password = "******";
            string expectedoutput_Noaccess = null;
            string expectedoutput_Access   = "userapi";

            string JSONapikey = HttpApiRequest.ClimateLogin(mail, password);

            if (mail == "test")
            {
                Assert.AreEqual(expectedoutput_Noaccess, JSONapikey);
            }
            else
            {
                Assert.IsTrue(JSONapikey.Contains(expectedoutput_Access));
            }
        }
Exemplo n.º 29
0
        private void btn_change_Click(object sender, RoutedEventArgs e)
        {
            if (tb_newpassword.Visibility == Visibility.Visible)
            {
                pb_newpassword.Password = tb_newpassword.Text;
            }
            if (tb_confirmnewpassword.Visibility == Visibility.Visible)
            {
                pb_confirmnewpassword.Password = tb_confirmnewpassword.Text;
            }

            if (pb_newpassword.Password != pb_confirmnewpassword.Password)
            {
                MessageBox.Show("New Password and Comfirm New Password does not match");
            }
            else
            {
                HttpApiRequest.ChangePassword(UserInformation.ApiKey, UserInformation.Mail, UserInformation.Password, pb_newpassword.Password);
                UserInformation.Password = pb_newpassword.Password;
                Close();
            }
        }
Exemplo n.º 30
0
        public async Task <TwitterTweetDTO> GetRecentTweetsByHashtagAsync(string hashtag)
        {
            IOAuthHelper oauth = new OAuthHelper();
            var          token = await oauth.GetToken();

            //TODO Need to set in constractor and pas through interfaces and Autofac
            ////////////////////////////////////////////////
            IApiParameter      parameter = new ApiParameter();
            IOAuthHelper       auth      = new OAuthHelper();
            IHttpRequestHeader header    = new Helpers.HttpRequestHeader();

            header.HeaderName  = "Authorization";
            header.HeaderValue = $"Bearer {token.access_token}";
            List <IApiParameter> parameters = new List <IApiParameter>();

            parameters.Add(new ApiParameter()
            {
                Name  = "q",
                Value = hashtag,
            });
            parameters.Add(new ApiParameter()
            {
                Name  = "since",
                Value = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd"),
            });
            parameters.Add(new ApiParameter()
            {
                Name  = "count",
                Value = "100",
            });

            IHttpApiRequest <Token>  request      = new HttpApiRequest <Token>(Enums.APIsListEnum.SearchForTweets, parameters, header);
            HttpClientHelper <Token> clientHelper = new HttpClientHelper <Token>(request);

            HttpResponseMessage response = new HttpResponseMessage();
            var tweets = await clientHelper.GettAsync <TwitterTweetDTO>();

            return(tweets);
        }
Exemplo n.º 31
0
        public override Task ApplyArgument(HttpApiRequest request, string name, object argument)
        {
            if (request.Body == null)
            {
                request.Body = new MultipartHttpBody();
            }
            var multipart = (MultipartHttpBody)request.Body;
            var body      = TypeConverter.ConvertTo <HttpBody>(TypeConversionContext.Body, argument);

            if (body == null)
            {
                throw new Exception($"Could not create body for {name}");
            }

            var contentType = body.Accept(new ContentTypeCalculator());

            multipart.Data[name] = new MultipartData
            {
                Body        = body,
                ContentType = contentType
            };

            return(base.ApplyArgument(request, name, argument));
        }
Exemplo n.º 32
0
 public async Task<HttpApiResponse> InstrumentCall(HttpApiRequest request, Func<HttpApiRequest, Task<HttpApiResponse>> inner)
 {
     request.Headers.Add(new HttpHeader("Test", "Value"));
     return await inner(request);
 }
Exemplo n.º 33
0
        public override Task ApplyArgument(HttpApiRequest request, string name, object argument)
        {
            request.Body = (HttpBody)argument;

            return(base.ApplyArgument(request, name, argument));
        }
Exemplo n.º 34
0
        /// <summary>
        /// To poplulate LiveChart in the GUI is only used by btn_Showdata_Click event
        /// </summary>
        private void PopulateCharts()
        {
            DataContext = null;
            DateTime date = dp_datestampfrom.SelectedDate.Value;

            string clvl = null;

            switch (cb_CompressionLVL.SelectedIndex)
            {
            case 0: clvl = "1"; break;

            case 1: clvl = "2"; break;

            case 2: clvl = "3"; break;

            case 3: clvl = "4"; break;

            default: break;
            }

            string unitID = null;

            foreach (var unit in units)
            {
                if (unit.name == cb_UnitID.Text)
                {
                    unitID = unit.id;
                }
            }

            string          climatestringdata = HttpApiRequest.GetClimateData(UserInformation.ApiKey, UserInformation.Mail, unitID, date.ToString("yyyy.MM.dd"), clvl);
            List <unitData> ClimateDataList   = JsonDataConverter.deserializedClimateData(climatestringdata);

            string format = "HH:mm";

            int x = ClimateDataList.Count();

            TimeLabel = new string[x];
            List <double> TemperaturValues = new List <double>();
            List <double> HeatIndexValues  = new List <double>();
            List <double> HumidityValues   = new List <double>();

            for (int i = 0; i < x; i++)
            {
                TimeLabel[i] = UnixStampConvert.UnixTimeToDateTime(ClimateDataList[i].datestamp).ToString(format);
                TemperaturValues.Add(Math.Round(ClimateDataList[i].climatedata.temperature, 2));
                HeatIndexValues.Add(Math.Round(ClimateDataList[i].climatedata.heatindex, 2));
                HumidityValues.Add(Math.Round(ClimateDataList[i].climatedata.humidity, 2));
            }

            var TempLineColor = Colors.Red;
            var HeatLineColor = Colors.Yellow;
            var HumiLineColor = Colors.Blue;

            SolidColorBrush TempLineColorfil = new SolidColorBrush();

            TempLineColorfil.Color   = TempLineColor;
            TempLineColorfil.Opacity = 0.2;

            SolidColorBrush HeatLineColorfil = new SolidColorBrush();

            HeatLineColorfil.Color   = HeatLineColor;
            HeatLineColorfil.Opacity = 0.2;

            SolidColorBrush HumiLineColorfil = new SolidColorBrush();

            HumiLineColorfil.Color   = HumiLineColor;
            HumiLineColorfil.Opacity = 0.2;

            TempSeries = new SeriesCollection
            {
                new LineSeries
                {
                    Title             = "Temperatur",
                    Values            = TemperaturValues.AsChartValues(),
                    LineSmoothness    = 1,
                    PointGeometrySize = 0,
                    Stroke            = Brushes.Red,
                    Fill = TempLineColorfil
                },
                new LineSeries
                {
                    Title             = "HeatIndex",
                    Values            = HeatIndexValues.AsChartValues(),
                    LineSmoothness    = 1,
                    PointGeometrySize = 0,
                    Stroke            = Brushes.Yellow,
                    Fill = HeatLineColorfil
                }
            };

            HumiSeries = new SeriesCollection
            {
                new LineSeries
                {
                    Title             = "Humidity",
                    Values            = HumidityValues.AsChartValues(),
                    LineSmoothness    = 1,
                    PointGeometrySize = 0,
                    Stroke            = Brushes.Blue,
                    Fill = HumiLineColorfil
                }
            };

            DataContext = this;
        }
Exemplo n.º 35
0
 public async Task<HttpApiResponse> InstrumentCall(HttpApiRequest request, Func<HttpApiRequest, Task<HttpApiResponse>> inner)
 {
     var response = await inner(request);
     response.Body = new JsonHttpBody("foo");
     return response;
 }
Exemplo n.º 36
0
        /// <summary>
        /// Function used to getunits with and without null in unit names
        /// </summary>
        /// <param name="FilterNull">true is no units with null in unit names</param>
        /// <returns>return a list of the units</returns>
        private List <Userunits> GetUnits(bool FilterNull)
        {
            string JSONunits = HttpApiRequest.Userunits(UserInformation.ApiKey, UserInformation.Mail, UserInformation.Password);

            return(JsonDataConverter.deserializedUnits(JSONunits, FilterNull));
        }
Exemplo n.º 37
0
 public Task <HttpHandlerResponse> Call(HttpApiRequest request)
 {
     Request = request.Clone();
     return(Task.FromResult(new HttpHandlerResponse(Response(request), TimeSpan.Zero, TimeSpan.Zero)));
 }
Exemplo n.º 38
0
 private void btn_save_Click(object sender, RoutedEventArgs e)
 {
     HttpApiRequest.Changeunits(UserInformation.ApiKey, UserInformation.Mail, units);
     DialogResult = true;
     Close();
 }
Exemplo n.º 39
0
 protected override Task<object> ProvideResult(HttpApiRequest request, HttpApiResponse response)
 {
     return Task.FromResult<object>(((StringHttpBody)response.Body).Text);
 }
Exemplo n.º 40
0
 protected override Task <object> ProvideResult(HttpApiRequest request, HttpApiResponse response)
 {
     return(Task.FromResult <object>(((StringHttpBody)response.Body).Text));
 }
 protected override Task <object> ProvideResult(HttpApiRequest request, HttpApiResponse response)
 {
     return(Task.FromResult <object>(response));
 }
Exemplo n.º 42
0
 protected override Task<object> ProvideResult(HttpApiRequest request, HttpApiResponse response)
 {
     return Task.FromResult<object>(null);
 }
Exemplo n.º 43
0
        public Task <HttpHandlerResponse> Call(HttpApiRequest request)
        {
            var webRequest = WebRequest.CreateHttp(request.Url.ToString());

            webRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
            webRequest.Method = request.Method.ToString();
            if (request.Proxy != null)
            {
                webRequest.Proxy = request.Proxy;
            }
            foreach (var header in request.Headers)
            {
                switch (header.Name)
                {
                case "User-Agent":
                    webRequest.UserAgent = header.Values.Single();
                    break;

                case "Accept":
                    webRequest.Accept = header.Values.Single();
                    break;

                case "Content-Type":
                    webRequest.ContentType = header.Values.Single();
                    break;

                default:
                    webRequest.Headers.Add(header.Name, string.Join(",", header.Values));
                    break;
                }
            }

            var requestWriteTime = new Stopwatch();

            requestWriteTime.Start();
            if (request.Body != null)
            {
                var requestStream = webRequest.GetRequestStream();
                var stream        = request.Body.Accept(new ContentCreator());
                stream.CopyTo(requestStream);
                requestStream.Close();
            }
            else if (request.Method != HttpMethod.Get && request.Method != HttpMethod.Head)
            {
                var requestStream = webRequest.GetRequestStream();
                requestStream.Close();
            }

            HttpWebResponse response;

            try
            {
                response = (HttpWebResponse)webRequest.GetResponse();
            }
            catch (WebException e) when(e.Response != null)
            {
                response = (HttpWebResponse)e.Response;
            }

            requestWriteTime.Stop();

            var      responseHeaders = new List <HttpHeader>();
            HttpBody responseBody    = null;

            responseHeaders.AddRange(response.Headers.AllKeys.Select(x => new HttpHeader(x, response.Headers[x].Split(','))));

            var responseReadTime = new Stopwatch();

            responseReadTime.Start();

            var responseStream = response.GetResponseStream();

            switch (request.ResponseContentTypeOverride ?? response.ContentType.Split(';')[0])
            {
            case "application/json":
                var jsonString = Encoding.UTF8.GetString(responseStream.ReadToEnd());
                var json       = !string.IsNullOrEmpty(jsonString) ? JToken.Parse(jsonString) : null;      // Hack to workaround silly servers that send a content type and a 204
                if (json != null)
                {
                    responseBody = new JsonHttpBody(json);
                }
                break;

            case "application/x-www-form-urlencoded":
                throw new NotSupportedException();

//                    var stream = await message.Content.ReadAsStreamAsync();
//                    body = FormParser.ParseForm(stream);
//                    break;
            case "text/plain":
            case "text/html":
            case "":
                var text = Encoding.UTF8.GetString(responseStream.ReadToEnd());
                responseBody = new StringHttpBody(text);
                break;

            case "application/octet-stream":
                var stream = new MemoryStream();
                responseStream.CopyTo(stream);
                stream.Position = 0;
                responseBody    = new StreamHttpBody(stream);
                break;
            }

            responseStream.Close();
            responseReadTime.Stop();

            var result = new HttpApiResponse(response.StatusCode, responseBody, responseHeaders, response.ResponseUri.ToString());

            return(Task.FromResult(new HttpHandlerResponse(result, requestWriteTime.Elapsed, responseReadTime.Elapsed)));
        }
Exemplo n.º 44
0
 public override Task <HttpHandlerResponse> GetResponse(HttpApiRequest request)
 {
     throw new Exception("Fail");
 }
Exemplo n.º 45
0
 public Task<HttpApiResponse> Call(HttpApiRequest request)
 {
     Request = request;
     return Task.FromResult(Response(request));
 }
Exemplo n.º 46
0
            public override async Task <HttpHandlerResponse> GetResponse(HttpApiRequest request)
            {
                await Task.Delay(1);

                throw new Exception("Fail");
            }
Exemplo n.º 47
0
        public override Task ApplyArgument(HttpApiRequest request, string name, object argument)
        {
            request.Body = (HttpBody)argument;

            return base.ApplyArgument(request, name, argument);
        }
Exemplo n.º 48
0
 public async Task<HttpApiResponse> InstrumentCall(HttpApiRequest request, Func<HttpApiRequest, Task<HttpApiResponse>> inner)
 {
     request.Headers.AddRange(Headers);
     return await inner(request);
 }