当前位置: 首页>>代码示例>>C++>>正文


C++ http_request::get_path方法代码示例

本文整理汇总了C++中http_request::get_path方法的典型用法代码示例。如果您正苦于以下问题:C++ http_request::get_path方法的具体用法?C++ http_request::get_path怎么用?C++ http_request::get_path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在http_request的用法示例。


在下文中一共展示了http_request::get_path方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: operator

    int operator() (const http_request& request, http_response* response)
    {
        char buf[256] = {0};
        std::string resp_body;
        std::vector<pid_t>::iterator it;
        std::string path_str;
        time_t time_now;

        ///只允许get方法
        http_request::request_method method = request.get_method();
        if (method != http_request::rGet)
            goto err;

        ///只允许请求/
        path_str =request.get_path();
        if (path_str != "/")
            return -1;

        if (request.get_request_head("Connection") == std::string("close")) {
            response->add_header("Connection", "close");
            response->set_close_conn(true);
        }

        snprintf(buf, sizeof(buf), "uid: %d \r\n", process_info::uid());
        resp_body = buf + process_info::username() + "\r\n" +
                    process_info::hostname() + "\r\n" + "\r\n";

        for (it = m_pid_vec_.begin(); it != m_pid_vec_.end(); ++it) {
            resp_body += process_info::get_proc_status(*it) + "\r\n";

            snprintf(buf, sizeof(buf), "opend Files: %d \r\n\r\n", process_info::get_opened_files(*it));
            resp_body += buf;
        }

        response->set_status_code(http_response::k200Ok);
        response->set_status_str("OK");
        response->add_header("Content-Type", "text/plain");
        response->add_header("Server", "async_serv");
        response->add_header("Connection", "keep-alive");

        ::time(&time_now);
        ::strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", ::gmtime(&time_now));
        response->add_header("Date", buf);

        response->set_body(resp_body);

        return 0;
err:
        return default_404_response(request, response);
    }
开发者ID:Zhanyin,项目名称:taomee,代码行数:50,代码来源:http_inspector.hpp

示例2: render

void RootResource::render(const http_request &request, http_response **response) {
    // Execute the appropriate handler function depending on the path or return a 404
    std::string path = request.get_path();
    std::string method = request.get_method();

    if (this->paths.find(path) != this->paths.end()) {
        // Found path - do we have an entry for the HTTP method being used?
        if (this->paths[path].find(method) != this->paths[path].end()) {
            // Found method so execute it and return
            // Sorry - this is dirty!
            (this->*(this->paths[path][method]))(request, response);
            return;
        }
    }

    // If we fall through to here then we didn't find anything - return 404
    *response = new http_response(http_response_builder("Not Found", 404).string_response());
}
开发者ID:liamfraser,项目名称:MADRAS,代码行数:18,代码来源:RootResource.cpp

示例3: render_GET

void FoldersService::render_GET(const http_request& req, http_response** res)
{
	Document respjsondoc;
	respjsondoc.SetArray();

	string strid = req.get_arg("id");
	HisDevFolder* folder = root->GetFolder();
	string path = req.get_path();
	if(!strid.empty())
	{
		CUUID id = CUUID::Parse(strid);
		folder = dynamic_cast<HisDevFolder*>(folder->Find(id));
	}

	if (path.find("/api/folders")!=string::npos)
	{
		if (folder!=NULL)
		{
			FoldersToJson(folder,respjsondoc);
		}
	}
	else if (path.find("/api/folder")!=string::npos)
	{
		if (folder!=NULL)
		{
			FolderToJson(folder,respjsondoc);
		}
	}


	StringBuffer buffer;
	PrettyWriter<StringBuffer> wr(buffer);
	respjsondoc.Accept(wr);
	std::string json = buffer.GetString();
	*res = new http_string_response(json, 200, "application/json");
}
开发者ID:jurda23,项目名称:homeis,代码行数:36,代码来源:FoldersService.cpp


注:本文中的http_request::get_path方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。