Example #1
0
void AppBusiness::onHttpSession(const HttpRequest& request, HttpResponse& response)
{
    string content = "this is a simple http server.";

    response.setStatusCode(200);
    response.getContentStream()->write(content.c_str(), content.length());
}
Example #2
0
void IseServerInspector::onHttpSession(const HttpRequest& request, HttpResponse& response)
{
    response.setCacheControl("no-cache");
    response.setPragma(response.getCacheControl());
    response.setContentType("text/plain");

    if (request.getUrl() == "/")
    {
        AutoLocker locker(mutex_);
        string s = outputHelpPage();

        response.setStatusCode(200);
        response.setContentType("text/html");
        response.getContentStream()->write(s.c_str(), static_cast<int>(s.length()));
    }
    else
    {
        AutoLocker locker(mutex_);
        string category, command;
        CommandItem *commandItem;
        PropertyList argList;

        if (parseCommandUrl(request, category, command, argList) &&
            (commandItem = findCommandItem(category, command)))
        {
            string contentType = response.getContentType();
            string s = commandItem->outputCallback(argList, contentType);

            response.setStatusCode(200);
            response.setContentType(contentType);
            response.getContentStream()->write(s.c_str(), static_cast<int>(s.length()));
        }
        else
        {
            string s = "Not Found";
            response.setStatusCode(404);
            response.getContentStream()->write(s.c_str(), static_cast<int>(s.length()));
        }
    }
}