Esempio n. 1
0
        /// <summary>
        /// 获得用于发送请求的Request对象
        /// </summary>
        /// <param name="uri">当前请求的目标地址</param>
        /// <param name="method">当前请求的HTTP方法</param>
        /// <param name="context">当前的上下文 <see cref="HttpContext" /></param>
        /// <returns></returns>
        public override HttpWebRequest GetRequest(Uri uri, string method, HttpContext context)
        {
            var req = (HttpWebRequest)WebRequest.Create(uri);

            req.Method = method;

            //客户端证书
            if (context.Client.Setting.X509Certificates?.Length > 0)
            {
                req.ClientCertificates.AddRange(context.Client.Setting.X509Certificates);
            }

            if (context.Request.X509Certificates?.Length > 0)
            {
                req.ClientCertificates.AddRange(context.Request.X509Certificates);
            }

            req.ServicePoint.BindIPEndPointDelegate = (servicePoint, rep, rc) => BindIPEndPoint(context, uri, method, servicePoint, rep, rc);

            var e = new HttpHandlerEventArgs(req, null);

            OnWebRequestCreated(e);

            return(e.HttpWebRequest);
        }
Esempio n. 2
0
        /// <summary>
        /// 引发 <see cref="HttpContextCreated" /> 事件
        /// </summary>
        /// <param name="ea">包含此事件的参数</param>
        protected virtual void OnHttpContextCreated(HttpHandlerEventArgs ea)
        {
            var handler = HttpContextCreated;

            if (handler != null)
            {
                handler(this, ea);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 引发 <see cref="RequestCreated" /> 事件
        /// </summary>
        /// <param name="ea">包含此事件的参数</param>
        protected virtual void OnRequestCreated(HttpHandlerEventArgs ea)
        {
            var handler = RequestCreated;

            if (handler != null)
            {
                handler(this, ea);
            }
        }
Esempio n. 4
0
		/// <summary>
		/// 创建上下文环境
		/// </summary>
		/// <param name="client"></param>
		/// <param name="request"></param>
		/// <returns></returns>
		public virtual HttpContext<T> GetContext<T>(HttpClient client, HttpRequestMessage request) where T : class
		{
			var ctx = new HttpContext<T>(client, request);

			//附加监听器
			if (client.Monitor != null)
				ctx.AttachMonitor(client.Monitor);

			var e = new HttpHandlerEventArgs(null, ctx);

			OnHttpContextCreated(e);

			return e.HttpContext as HttpContext<T>;
		}
Esempio n. 5
0
		/// <summary>
		/// 创建上下文环境
		/// </summary>
		/// <param name="client"></param>
		/// <param name="request"></param>
		/// <returns></returns>
		public virtual HttpContext GetContext(HttpClient client, HttpRequestMessage request)
		{
			//证书
			client.Setting.CertificateManager?.SetRequest(request);

			var ctx = new HttpContext(client, request);
			
			//附加监听器
			if (client.Monitor != null)
				ctx.AttachMonitor(client.Monitor);

			var e = new HttpHandlerEventArgs(null, ctx);

			OnHttpContextCreated(e);

			return e.HttpContext;
		}
Esempio n. 6
0
 /// <summary>
 /// 引发 <see cref="HttpHandler.WebRequestCreated.WebRequestCreated" /> 事件
 /// </summary>
 /// <param name="ea">包含此事件的参数</param>
 public virtual void OnWebRequestCreated(HttpHandlerEventArgs ea) => WebRequestCreated?.Invoke(ea.HttpContext, ea);