Commit 4f7babcf authored by jan.koester's avatar jan.koester
Browse files

test

parent b6724199
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -65,13 +65,25 @@ webedit::Server::~Server() {

std::string webedit::Server::getCookie(libhttppp::HttpRequest &curreq,
                                        const std::string &name) {
    auto normalizeCookieValue = [](std::string value) {
        while (!value.empty() && std::isspace(static_cast<unsigned char>(value.front())))
            value.erase(value.begin());
        while (!value.empty() && std::isspace(static_cast<unsigned char>(value.back())))
            value.pop_back();

        if (value.size() >= 2 && value.front() == '"' && value.back() == '"')
            value = value.substr(1, value.size() - 2);

        return value;
    };

    try {
        libhttppp::HttpCookie cookie;
        cookie.parse(curreq);
        auto *cd = cookie.getfirstCookieData();
        while (cd) {
            if (cd->getKey() == name)
                return cd->getValue();
                return normalizeCookieValue(cd->getValue());
            cd = cd->nextCookieData();
        }
    } catch (...) {