Skip to content

Cannot register multiple endpoints #47

Closed

Description

@JeremyLWright

Included is a test case to register multiple endpoints. This test fails. Is this a bug, or a misuse of the API? If this is bug, will you please confirm this is a valid test case, and I will continue diving into it. Thank you for your time.

Sincerely,
Jeremy Wright

class Ok_resource : public http_resource<Ok_resource>
{
    public:
        void render_GET(const http_request& req, http_response** res)
        {
            *res = new http_string_response("OK", 200, "text/plain");
        }
};

class Nok_resource : public http_resource<Nok_resource>
{
    public:
        void render_GET(const http_request& req, http_response** res)
        {
            *res = new http_string_response("NOK", 200, "text/plain");
        }
};

LT_BEGIN_AUTO_TEST(basic_suite, two_endpoints)

    Ok_resource* ok = new Ok_resource();
    ws->register_resource("OK", ok);
    Nok_resource* nok = new Nok_resource();
    ws->register_resource("NOK", nok);

    curl_global_init(CURL_GLOBAL_ALL);
    std::string s;
    {
        CURL *curl = curl_easy_init();
        CURLcode res;
        curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/OK");
        curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
        res = curl_easy_perform(curl);
        LT_ASSERT_EQ(res, 0);
        LT_CHECK_EQ(s, "OK");
        curl_easy_cleanup(curl);
    }

    std::string t;
    {        
        CURL *curl = curl_easy_init();
        CURLcode res;
        curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/NOK");
        curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &t);
        res = curl_easy_perform(curl);
        LT_ASSERT_EQ(res, 0);
        LT_CHECK_EQ(t, "NOK");
        curl_easy_cleanup(curl);
    }

LT_END_AUTO_TEST(two_endpoints)

Activity

  1. etr commented on Apr 3, 2014

    @etr
    Owner

    you actually spotted 2 different bugs.
    The first one regarded the server creation - it was always created as a single resource.
    The second one regarded the case insensitivity of the URL - it was always used in a case insensitive way.

    Thanks for notifying :). It should be everything fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions