/// <summary> /// Gets the response in string from HttpResponseBuffer. /// </summary> /// <param name="url">Url for which response is needed</param> /// <returns></returns> private string GetResponseForUrl(string url, string filePath, HttpListenerContext ctx) { string retVal = string.Empty; HttpResponseBuffer responseBuffer = null; responseBuffer = _httpUrlList.GetUrl(url); if (responseBuffer != null) { if ((DateTime.UtcNow.Ticks > responseBuffer.ExpiryTime) && (responseBuffer.IgnoreExpiryTime == false)) { ctx.Response.StatusCode = 400; _logger.Error(string.Format(Constants.URL_TIMEDOUT, url)); } else { retVal = responseBuffer.GetData(); } } else { ctx.Response.StatusCode = 403; _logger.Error(string.Format(Constants.LOG_RESOURCENOTFOUND, url)); } return(retVal); }
/// <summary> /// Adds Url and object of HttpResponseBuffer to ConcurrentDictionary /// </summary> /// <param name="Url"> Url that is called by the user agent.</param> /// <param name="session">Session is an object HttpResponseBuffer. See HttpResponseBuffer documentation for more.</param> //ToDo : Failure checks public bool AddUrl(string Url, HttpResponseBuffer session) { bool retVal = false; if (string.IsNullOrEmpty(Url)) { _logger.Error(string.Format(Constants.LOG_RESOURCEUNABLETOADD, Url)); } else { Url = Url.ToLower(); if (_httpUrlList.ContainsKey(Url)) { HttpResponseBuffer val; _httpUrlList.TryGetValue(Url, out val); retVal = _httpUrlList.TryUpdate(Url, session, val); } else { retVal = _httpUrlList.TryAdd(Url, session); } if (retVal == true) { _logger.Info(string.Format(Constants.LOG_RESOURCEADDED, Url)); } else { _logger.Error(string.Format(Constants.LOG_RESOURCEUNABLETOADD, Url)); } } return(retVal); }
/// <summary> /// Updates the Expiry of a url, by already given TimeOut parameter. /// </summary> /// <param name="url">Url for which expiry times need to updated.</param> /// <param name="seconds">Time in seconds.</param> public void PokeUrl(string url) { url = Utilities.CleanUnixUrl(url); HttpResponseBuffer buffer = _httpUrlList.GetUrl(url); if (buffer != null) { buffer.ExtendExpiryTime(); } else { _logger.Error(string.Format(Constants.LOG_RESOURCENOTFOUND, url)); } }
/// <summary> /// Removes the Url and the object from ConcurrentDictionary. /// </summary> /// <param name="Url">Url which needs to be removed</param> public bool RemoveUrl(string Url) { bool retVal = false; HttpResponseBuffer responseBuffer = null; if (Url == null) { _logger.Error(Constants.NULL_PATH_URL + Utilities.GetMethodName()); } else { Url = Url.ToLower(); if (_httpUrlList.TryRemove(Url, out responseBuffer) == true) { retVal = true; _logger.Info(string.Format(Constants.LOG_RESOURCEREMOVED, Url)); } else { _logger.Error(string.Format(Constants.LOG_RESOURCENOTREMOVED, Url)); } } return(retVal); }
/// <summary> /// Gets HttpResponseBuffer object aligned with strUrl. /// </summary> /// <param name="strUrl">Url against which the response Buffer is extracted.</param> /// <returns></returns> public HttpResponseBuffer GetUrl(string strUrl) { HttpResponseBuffer responseBuffer = null; if (strUrl == null) { _logger.Error(Constants.NULL_PATH_URL + Utilities.GetMethodName()); } else { strUrl = strUrl.ToLower(); if (_httpUrlList.TryGetValue(strUrl, out responseBuffer) == true) { _logger.Info(string.Format(Constants.LOG_RESOURCEFOUND, strUrl)); } else { _logger.Error(string.Format(Constants.LOG_RESOURCENOTFOUND, strUrl)); } } return(responseBuffer); }