public void EmptyTzName() { string tzName = string.Empty; var http = new BasicHttpContext(); SrkHttpContextExtensions.SetTimezone(http, tzName); }
public void InvalidTzName() { string tzName = "Lunar Standard Time"; var http = new BasicHttpContext(); SrkHttpContextExtensions.SetTimezone(http, tzName); }
public void NullTzName() { string tzName = null; var http = new BasicHttpContext(); SrkHttpContextExtensions.SetTimezone(http, tzName); }
public void WorksWithTzObject() { var tz = TimeZoneInfo.FindSystemTimeZoneById("Romance Standard Time"); var http = new BasicHttpContext(); SrkHttpContextExtensions.SetTimezone(http, tz); Assert.IsNotNull(http.Items["Timezone"]); Assert.AreEqual(tz, http.Items["Timezone"]); }
public void GetterWorks() { var tzName = "Romance Standard Time"; var tz = TimeZoneInfo.FindSystemTimeZoneById(tzName); var http = new BasicHttpContext(); SrkHttpContextExtensions.SetTimezone(http, tzName); var result = SrkHttpContextExtensions.GetTimezone(http); Assert.IsNotNull(result); Assert.AreEqual(tz, result); }
public static HtmlHelper CreateHtmlHelper(ViewDataDictionary vd) { var httpContext = new BasicHttpContext(); var mockViewContext = new ViewContext( new ControllerContext( httpContext, new RouteData(), new Mock <ControllerBase>().Object), new Mock <IView>().Object, vd, new TempDataDictionary(), new Mock <TextWriter>().Object); var mockViewDataContainer = new Mock <IViewDataContainer>(); mockViewDataContainer.Setup(v => v.ViewData) .Returns(vd); return(new HtmlHelper(mockViewContext, mockViewDataContainer.Object)); }
private static HtmlHelper GetHtmlHelper(TestModel model) { var http = new BasicHttpContext(); var viewData = new ViewDataDictionary(model); var controllerContext = new ControllerContext(); controllerContext.HttpContext = http; var viewDataContainer = new ViewPage(); var view = new Mock <IView>(); var tempData = new TempDataDictionary(); var writer = new StreamWriter(new MemoryStream()); var viewContext = new ViewContext(controllerContext, view.Object, viewData, tempData, writer); viewContext.HttpContext = http; var html = new HtmlHelper(viewContext, viewDataContainer); html.ViewContext.HttpContext = http; var modelState = html.ViewData.ModelState; return(html); }
public virtual string httpGet(string url) { string domain = Resources.getString([email protected]_domain); string result = ""; CookieStore cookieStore = new BasicCookieStore(); BasicHttpContext localContext = new BasicHttpContext(); localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); // If we have a cookie stored, parse and use it. Otherwise, use a default http client. try { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); if (!authorizationCookie.Equals("")) { string[] cookies = authorizationCookie.Split(";", true); for (int i = 0; i < cookies.Length; i++) { string[] kvp = cookies[i].Split("=", true); if (kvp.Length != 2) { throw new Exception("Illegal cookie: missing key/value pair."); } BasicClientCookie c = new BasicClientCookie(kvp[0], kvp[1]); c.Domain = domain; cookieStore.addCookie(c); } } HttpResponse httpResponse = httpClient.execute(httpGet, localContext); result = EntityUtils.ToString(httpResponse.Entity); } catch (Exception e) { Log.e(TAG, e.LocalizedMessage); } return(result); }
/// <exception cref="System.IO.IOException"></exception> /// <exception cref="Apache.Http.HttpException"></exception> public virtual Socket Tunnel(HttpHost proxy, HttpHost target, Credentials credentials ) { Args.NotNull(proxy, "Proxy host"); Args.NotNull(target, "Target host"); Args.NotNull(credentials, "Credentials"); HttpHost host = target; if (host.GetPort() <= 0) { host = new HttpHost(host.GetHostName(), 80, host.GetSchemeName()); } HttpRoute route = new HttpRoute(host, this.requestConfig.GetLocalAddress(), proxy , false, RouteInfo.TunnelType.Tunnelled, RouteInfo.LayerType.Plain); ManagedHttpClientConnection conn = this.connFactory.Create(route, this.connectionConfig ); HttpContext context = new BasicHttpContext(); HttpResponse response; IHttpRequest connect = new BasicHttpRequest("CONNECT", host.ToHostString(), HttpVersion .Http11); BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.SetCredentials(new AuthScope(proxy), credentials); // Populate the execution context context.SetAttribute(HttpCoreContext.HttpTargetHost, target); context.SetAttribute(HttpCoreContext.HttpConnection, conn); context.SetAttribute(HttpCoreContext.HttpRequest, connect); context.SetAttribute(HttpClientContext.HttpRoute, route); context.SetAttribute(HttpClientContext.ProxyAuthState, this.proxyAuthState); context.SetAttribute(HttpClientContext.CredsProvider, credsProvider); context.SetAttribute(HttpClientContext.AuthschemeRegistry, this.authSchemeRegistry ); context.SetAttribute(HttpClientContext.RequestConfig, this.requestConfig); this.requestExec.PreProcess(connect, this.httpProcessor, context); for (; ;) { if (!conn.IsOpen()) { Socket socket = Sharpen.Extensions.CreateSocket(proxy.GetHostName(), proxy.GetPort ()); conn.Bind(socket); } this.authenticator.GenerateAuthResponse(connect, this.proxyAuthState, context); response = this.requestExec.Execute(connect, conn, context); int status = response.GetStatusLine().GetStatusCode(); if (status < 200) { throw new HttpException("Unexpected response to CONNECT request: " + response.GetStatusLine ()); } if (this.authenticator.IsAuthenticationRequested(proxy, response, this.proxyAuthStrategy , this.proxyAuthState, context)) { if (this.authenticator.HandleAuthChallenge(proxy, response, this.proxyAuthStrategy , this.proxyAuthState, context)) { // Retry request if (this.reuseStrategy.KeepAlive(response, context)) { // Consume response content HttpEntity entity = response.GetEntity(); EntityUtils.Consume(entity); } else { conn.Close(); } // discard previous auth header connect.RemoveHeaders(AUTH.ProxyAuthResp); } else { break; } } else { break; } } int status_1 = response.GetStatusLine().GetStatusCode(); if (status_1 > 299) { // Buffer response content HttpEntity entity = response.GetEntity(); if (entity != null) { response.SetEntity(new BufferedHttpEntity(entity)); } conn.Close(); throw new TunnelRefusedException("CONNECT refused by proxy: " + response.GetStatusLine (), response); } return(conn.GetSocket()); }