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


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

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


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

示例1: post

TEST(WriteResponse, test_WriteResponse)
{
    HttpResponse response;
    ASSERT_EQ(WriteResponse(-1, response), -1);

    int fd = open("httpResponse.txt", O_WRONLY | O_CREAT);
    response.SetHttpVersion("HTTP/1.0");
    response.SetStatusAndReason("200", "OK");

    string post("POST_BEGIN\r\nPOST_MID\r\n\r\nPOST_END");
    response.SetStatusAndReason("200", "OK");
    response.SetHeaderParam("Content-Length", IntToStr(post.size()));

    // [response] will be responsible for free [data]
    char* data = CreateCStr(post.size() + 1);
    sprintf(data, "%s", post.c_str());
    response.SetBodyAndLen(data, post.size());
    ASSERT_EQ(WriteResponse(fd, response), 0);
    close(fd);

    fd = open("httpResponse.txt", O_RDONLY);
    if (fd < 0)
    {
        ASSERT_TRUE(false);
    }
    char* buf = CreateCStr(BUF_SIZE);
    readn(fd, buf, BUF_SIZE);

    string expected = "HTTP/1.0 200 OK\r\nContent-Length: 32\r\n"
        "\r\n"
        "POST_BEGIN\r\nPOST_MID\r\n\r\nPOST_END";
    ASSERT_STREQ(buf, expected.c_str());
    close(fd);
    delete [] buf;
}
开发者ID:moshangliu,项目名称:sources,代码行数:35,代码来源:test_Common.cpp

示例2: open

TEST(SetAndWriteBack, test_SetAndWriteBack_no_msgbody)
{
    int fd = open("./setAndWriteBack.txt", O_WRONLY | O_CREAT);
    if (fd < 0)
    {
        ASSERT_TRUE(false);
        return;
    }

    HttpResponse response;
    response.SetHttpVersion("HTTP/1.0");
    SetAndWriteBack(fd, response, "400", "Bad Request");
    close(fd);

    fd = open("./setAndWriteBack.txt", O_RDONLY);
    char* buf = CreateCStr(BUF_SIZE);
    readn(fd, buf, BUF_SIZE);

    const char* expected = "HTTP/1.0 400 Bad Request\r\n"
        "Content-Length: 0\r\n"
        "Content-Type: text/html\r\n"
        "\r\n";
    ASSERT_STREQ(buf, expected);
}
开发者ID:moshangliu,项目名称:sources,代码行数:24,代码来源:test_Common.cpp


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