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


C++ HttpResponse::getMap方法代码示例

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


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

示例1: do_child

void do_child(int fd, char* dir){
    int recvLen = 0;
    int p_size = 0;
    std::vector<char> pload;
    char buf[500] = {0};
    memset(buf, '\0', sizeof(buf));
    
    char filepath[100];
    
    struct timeval tv;
    tv.tv_sec = 40;
    tv.tv_usec = 0;
    setsockopt (fd, SOL_SOCKET, SO_RCVTIMEO, (char*)&tv, sizeof(struct timeval));
    std::vector <char> wire;
    std::vector <char> res_wire;
    
    while (true){
    strcpy(filepath, dir);
    bool isdone = false;
    struct timeval tv;
    tv.tv_sec = 30;
    tv.tv_usec = 0;
    setsockopt (fd, SOL_SOCKET, SO_RCVTIMEO, (char*)&tv, sizeof(struct timeval));
    while(1){
        memset(buf, '\0', sizeof(buf));
        if ((recvLen = recv(fd, buf, 500, 0)) == -1) {
            std::cout << "Timeout expires" << std::endl;
            perror("recv");
            close(fd);
            return;
        }
        for (int i =0; i < recvLen; i++)
        {
            wire.push_back(buf[i]);
            if(buf[i] == '\r' && buf[i+1] == '\n' && buf[i+2] == '\r' && buf[i+3] == '\n')
            {
                wire.push_back(buf[i+1]);
                wire.push_back(buf[i+2]);
                wire.push_back(buf[i+3]);
                isdone = true;
                break;
            }
        }
        if(isdone == true)
            break;
    }
        
        std::cout << "Received the request message: "<<std::endl;
        for (int i = 0; i<wire.size(); i++) {
            std::cout << wire[i];
        }
        std::cout << std::endl;
        
        HttpRequest request;
        request.decodeFirstLine(wire);
        request.decodeHeaderline(wire);
        wire.clear();
        HttpResponse response;
        response.setVersion(request.getVersion());
        HttpStatus status;
        bool set_status = false;
    
        if(request.getMap("Connection") == "Keep-Alive")
            response.setHeader("Connection", "Keep-Alive");
        else if(request.getMap("Connection") == "Close")
            response.setHeader("Connection", "Close");
        else
        {
            if(set_status == false){
            status.m_statuscode = "400";
            response.setStatus(status);
            response.setDescription ("Bad Request");
            response.setHeader("Content-Length", "0");
            set_status = true;
            }
        }
    
        std::string recurl = request.getUrl();

        int len = recurl.length();
        int i = 0;
    
        if(recurl[i] == 'h'&& recurl[i+1] == 't' && recurl[i+2] == 't' && recurl[i+3] == 'p' &&recurl[i+4] ==':' && recurl[i+5]=='/' &&recurl[i+6] == '/')
        {
            i+=7;
            char host_check[200] = {'\0'};
            int pt_check = -1;
            int j = 0;
            while (i < len)
            {
                if(recurl[i]!= '/' && recurl[i]!= ':')
                {
                    host_check[j] = recurl[i];
                    j++;
                    i++;
                }
                else
                    break;
            }
            std::string mycheck = host_check;
//.........这里部分代码省略.........
开发者ID:louis-wuitton,项目名称:CS-118,代码行数:101,代码来源:web-server.cpp


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