Esempio n. 1
0
        /// <summary>
        /// Registers for notification for when the specified method is received in a HttpRequest
        /// </summary>
        /// <param name="method">The method notification will be registered for</param>
        /// <param name="onRequest">The callback to be notified when/if the method is received</param>
        public void RegisterForRequestMethodNotification(string method, EventHandler <HttpRequestCancelEventArgs> onRequest)
        {
            // we must have a valid method
            HttpUtils.ValidateToken(@"method", method);

            // and we must have a valid callback
            if (onRequest == null)
            {
                throw new ArgumentNullException("onRequest");
            }

            // look up the list of handlers for the specified hook point, and then look up the method in that list to
            Hashtable requestHandlers = this[HttpRequestHookPoints.BeforeHttpRuntimeProcessing];

            // receive the list of handlers that is handling callback notification for methods in that list
            EventHandler <HttpRequestCancelEventArgs> handlers = requestHandlers[method] as EventHandler <HttpRequestCancelEventArgs>;

            // if the handler list is null
            if (handlers == null)
            {
                // add the handlers into the list by the method we're registering for
                requestHandlers.Add(method, handlers);
            }

            // now combine the callback with all of the existing handlers
            handlers = (EventHandler <HttpRequestCancelEventArgs>)Delegate.Combine(handlers, onRequest);

            // and finally store that list of callbacks using the method as the key in the list from which we retrieved this initially
            requestHandlers[method] = handlers;
        }
        /// <summary>
        /// Write the value to the specified header, optionally deletes the header if the value is empty or null
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="deleteIfEmptyOrNull"></param>
        public virtual void WriteHeaderValue(string name, string value, bool deleteIfNullOrEmpty)
        {
            if (deleteIfNullOrEmpty)
            {
                if (HttpUtils.IsEmptryString(value) || HttpUtils.IsNullString(value))
                {
                    _headers.Remove(name);
                    return;
                }
            }

            // validate the header value, not empty, null, or contains CR or LF
            HttpUtils.ValidateToken(name, value);

            // otherwise if it doesn't exist
            if (!_headers.Contains(name))
            {
                // add it in with the value specified
                _headers.Add(new HttpHeader(name, value));
                return;
            }

            // or finally just update the one that exists
            _headers[name].Value = value;
        }
Esempio n. 3
0
//		/// <summary>
//		/// Registers for notification for when the specified method is received in a HttpRequest
//		/// </summary>
//		/// <param name="method">The method notification will be registered for</param>
//		/// <param name="onRequest">The callback to be notified when/if the method is received</param>
//		public void RegisterForRequestMethodNotification(string method, HttpRequestEventHandler onRequest)
//		{
//			// we must have a valid method
//			HttpUtils.ValidateToken(@"method", method);
//
//			// and we must have a valid callback
//			if (onRequest == null)
//				throw new ArgumentNullException("onRequest");
//
//			// look up the list of handlers for the specified hook point, and then look up the method in that list to
//			Hashtable requestHandlers = this[HttpRequestHookPoints.AfterHttpRuntimeProcessing];
//
//			// receive the list of handlers that is handling callback notification for methods in that list
//			HttpRequestEventHandler handlers = requestHandlers[method] as HttpRequestEventHandler;
//
//			// if the handler list is null
//			if (handlers == null)
//				// add the handlers into the list by the method we're registering for
//				requestHandlers.Add(method, handlers);
//
//			// now combine the callback with all of the existing handlers
//			handlers = (HttpRequestEventHandler)Delegate.Combine(handlers, onRequest);
//
//			// and finally store that list of callbacks using the method as the key in the list from which we retrieved this initially
//			requestHandlers[method] = handlers;
//		}

        /// <summary>
        /// Unregisters for notification for when the specified method is received in a HttpRequest
        /// </summary>
        /// <param name="method">The method notification was registered for</param>
        /// <param name="onRequest">The callback to be notified when/if the method is received</param>
        public void UnregisterForRequestMethodNotification(string method, EventHandler <HttpRequestCancelEventArgs> onRequest)
        {
            // we must have a valid method
            HttpUtils.ValidateToken(@"method", method);

            // and we must have a valid callback
            if (onRequest == null)
            {
                throw new ArgumentNullException("onRequest");
            }

            // look up the list of handlers for the specified hook point, and then look up the method in that list to
            Hashtable requestHandlers = this[HttpRequestHookPoints.BeforeHttpRuntimeProcessing];

            // receive the list of handlers that is handling callback notification for methods in that list
            EventHandler <HttpRequestCancelEventArgs> handlers = requestHandlers[method] as EventHandler <HttpRequestCancelEventArgs>;

            // if the handler list is null
            if (handlers != null)
            {
                // add the handlers into the list by the method we're registering for
                handlers = (EventHandler <HttpRequestCancelEventArgs>)Delegate.Remove(handlers, onRequest);
            }

            // if there are still some handlers, and the list is zero length, remove the list entirely
            if (handlers != null)
            {
                if (handlers.GetInvocationList().Length == 0)
                {
                    requestHandlers.Remove(method);
                    return;
                }
            }

            // save the list of handlers for the next guy
            requestHandlers[method] = handlers;
        }