/// <summary> /// Add a powerful Agent handler to the underlying HTTP /// server. /// </summary> /// <param name="agentName">name of agent handler</param> /// <param name="handler">agent handler method</param> /// <returns>false when the plugin is disabled or the agent /// handler could not be added. Any generated exceptions are /// allowed to drop through to the caller, i.e. ArgumentException. /// </returns> public bool AddAgentHandler(string agentName, IHttpAgentHandler handler) { if (!IsEnabled) { return(false); } _agents.Add(agentName, handler); return(_httpd.AddAgentHandler(agentName, handler)); }
/// <summary> /// Remove a powerful Agent handler from the underlying HTTP /// server. /// </summary> /// <param name="agentName">name of agent handler</param> /// <param name="handler">agent handler method</param> /// <returns>false when the plugin is disabled or the agent /// handler could not be removed. Any generated exceptions are /// allowed to drop through to the caller, i.e. KeyNotFound. /// </returns> public bool RemoveAgentHandler(string agentName, IHttpAgentHandler handler) { if (!IsEnabled) { return(false); } if (_agents[agentName] == handler) { _agents.Remove(agentName); return(_httpd.RemoveAgentHandler(agentName, handler)); } return(false); }
private bool TryGetAgentHandler(OSHttpRequest request, OSHttpResponse response, out IHttpAgentHandler agentHandler) { agentHandler = null; lock (m_agentHandlers) { foreach (IHttpAgentHandler handler in m_agentHandlers.Values) { if (handler.Match(request, response)) { agentHandler = handler; return true; } } } return false; }
// Note that the agent string is provided simply to differentiate // the handlers - it is NOT required to be an actual agent header // value. public bool AddAgentHandler(string agent, IHttpAgentHandler handler) { lock (m_agentHandlers) { if (!m_agentHandlers.ContainsKey(agent)) { m_agentHandlers.Add(agent, handler); return true; } } //must already have a handler for that path so return false return false; }
public bool RemoveAgentHandler(string agent, IHttpAgentHandler handler) { lock (m_agentHandlers) { IHttpAgentHandler foundHandler; if (m_agentHandlers.TryGetValue(agent, out foundHandler) && foundHandler == handler) { m_agentHandlers.Remove(agent); return true; } } return false; }
/// <summary> /// A specific agent handler was provided. Such a handler is expecetd to have an /// intimate, and highly specific relationship with the client. Consequently, /// nothing is done here. /// </summary> /// <param name="handler"></param> /// <param name="request"></param> /// <param name="response"></param> private bool HandleAgentRequest(IHttpAgentHandler handler, OSHttpRequest request, OSHttpResponse response) { // In the case of REST, then handler is responsible for ALL aspects of // the request/response handling. Nothing is done here, not even encoding. try { return handler.Handle(request, response); } catch (Exception e) { // If the handler did in fact close the stream, then this will blow // chunks. So that that doesn't disturb anybody we throw away any // and all exceptions raised. We've done our best to release the // client. try { m_log.Warn("[HTTP-AGENT]: Error - " + e.Message); response.SendChunked = false; response.KeepAlive = true; response.StatusCode = (int)OSHttpStatusCode.ServerErrorInternalError; //response.OutputStream.Close(); try { response.Send(); //response.FreeContext(); } catch (SocketException f) { // This has to be here to prevent a Linux/Mono crash m_log.WarnFormat( "[BASE HTTP SERVER]: XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", f); } } catch(Exception) { } } // Indicate that the request has been "handled" return true; }
private bool TryGetAgentHandler(OSHttpRequest request, OSHttpResponse response, out IHttpAgentHandler agentHandler) { agentHandler = null; try { foreach (IHttpAgentHandler handler in m_agentHandlers.Values) { if (handler.Match(request, response)) { agentHandler = handler; return true; } } } catch(KeyNotFoundException) { } return false; }
public bool RemoveAgentHandler(string agent, IHttpAgentHandler handler) { try { if (handler == m_agentHandlers[agent]) { m_agentHandlers.Remove(agent); return true; } } catch(KeyNotFoundException) { } return false; }
/// <summary> /// Remove a powerful Agent handler from the underlying HTTP /// server. /// </summary> /// <param name="agentName">name of agent handler</param> /// <param name="handler">agent handler method</param> /// <returns>false when the plugin is disabled or the agent /// handler could not be removed. Any generated exceptions are /// allowed to drop through to the caller, i.e. KeyNotFound. /// </returns> public bool RemoveAgentHandler(string agentName, IHttpAgentHandler handler) { if (!IsEnabled) return false; if (_agents[agentName] == handler) { _agents.Remove(agentName); return _httpd.RemoveAgentHandler(agentName, handler); } return false; }
/// <summary> /// Add a powerful Agent handler to the underlying HTTP /// server. /// </summary> /// <param name="agentName">name of agent handler</param> /// <param name="handler">agent handler method</param> /// <returns>false when the plugin is disabled or the agent /// handler could not be added. Any generated exceptions are /// allowed to drop through to the caller, i.e. ArgumentException. /// </returns> public bool AddAgentHandler(string agentName, IHttpAgentHandler handler) { if (!IsEnabled) return false; _agents.Add(agentName, handler); return _httpd.AddAgentHandler(agentName, handler); }