Esempio n. 1
0
File: main.cpp Progetto: DavadDi/acl
    // 处理 text/plain 数据体
    bool do_plain(http_response& res, const char* req_charset, string& err)
    {
        string body;
        if (res.get_body(body, local_charset_) == false)
        {
            err += "get_body error";
            return false;
        }
        printf("body:\r\n(%s)\r\n", body.c_str());

        // 设置响应头字段
        http_header& header = res.response_header();
        string ctype("text/plain");
        if (req_charset)
        {
            ctype << "; charset=" << req_charset;
            header.set_content_type(ctype);
        }
        else
            header.set_content_type(ctype);

        printf(">>ctype: %s\r\n", ctype.c_str());

        // 发送响应体数据
        return response_body(res, body, req_charset);
    }
Esempio n. 2
0
File: main.cpp Progetto: DavadDi/acl
    // 处理 text/json 数据
    bool do_json(http_response& res, const char* req_charset, string& err)
    {
        json body;
        if (res.get_body(body, local_charset_) == false)
        {
            err += "get_body error";
            return false;
        }

        json_node* node = body.first_node();
        while (node)
        {
            if (node->tag_name())
            {
                printf("tag: %s", node->tag_name());
                if (node->get_text())
                    printf(", value: %s\r\n", node->get_text());
                else
                    printf("\r\n");
            }
            node = body.next_node();
        }

        // 设置响应头字段
        http_header& header = res.response_header();
        string ctype("text/json");
        if (req_charset)
        {
            ctype << "; charset=" << req_charset;
            header.set_content_type(ctype);
        }
        else
            header.set_content_type(ctype);

        printf(">>ctype: %s\r\n", ctype.c_str());

        // 构建响应体数据,并发送响应体数据
        string buf;
        body.build_json(buf);

        // 发送响应体数据
        return response_body(res, buf, req_charset);
    }
Esempio n. 3
0
File: main.cpp Progetto: DavadDi/acl
    // 处理 text/xml 数据体
    bool do_xml(http_response& res, const char* req_charset, string& err)
    {
        xml body;
        if (res.get_body(body, local_charset_) == false)
        {
            err += "get_body error";
            return false;
        }
        xml_node* node = body.first_node();
        while (node)
        {
            const char* tag = node->tag_name();
            const char* name = node->attr_value("name");
            const char* pass = node->attr_value("pass");
            printf(">>tag: %s, name: %s, pass: %s\r\n",
                   tag ? tag : "null",
                   name ? name : "null",
                   pass ? pass : "******");
            node = body.next_node();
        }

        // 设置响应头字段
        http_header& header = res.response_header();
        string ctype("text/xml");
        if (req_charset)
        {
            ctype << "; charset=" << req_charset;
            header.set_content_type(ctype);
        }
        else
            header.set_content_type(ctype);

        printf(">>ctype: %s\r\n", ctype.c_str());

        // 构建响应体数据,并发送响应体数据
        string buf;
        body.build_xml(buf);

        // 发送响应体数据
        return response_body(res, buf, req_charset);
    }