@@ -66,12 +66,12 @@ Session::~Session() {
6666}
6767
6868void Session::setCookie (std::string_view cookie) const {
69- log::log ().print (" Savig cookies: EJSID = {}" , cookie);
69+ log::log ().print (" Saving cookies: EJSID = {}" , cookie);
7070 client_.cookie (fmt::format (" {}\t FALSE\t /\t FALSE\t 0\t EJSID\t {}" , domain (), cookie));
7171}
7272
7373void Session::saveSession () const {
74- log::log ().print (" Savig token: {}" , domain (), token_);
74+ log::log ().print (" Saving token: {}" , domain (), token_);
7575 std::ofstream token (config_.file (config::FileType::token));
7676 fmt::print (token, " {}" , token_);
7777}
@@ -160,14 +160,15 @@ std::string Session::buildUrl(std::string_view base) {
160160
161161html::Html Session::getPage (std::string_view base, std::string_view params) {
162162 return getter (
163- base, params, [this ](auto base, auto params) { return getPageImpl (base, params); });
163+ base, params, [this ](auto base, auto params) { return getImpl (base, params). second ; });
164164}
165165
166166std::string_view Session::getRaw (std::string_view base, std::string_view params) {
167- return getter (base, params, [this ](auto base, auto params) { return getImpl (base, params); });
167+ return getter (
168+ base, params, [this ](auto base, auto params) { return getImpl (base, params).first ; });
168169}
169170
170- std::string_view Session::getImpl (std::string_view base, std::string_view params) {
171+ std::string_view Session::rawGetter (std::string_view base, std::string_view params) {
171172 std::string url = buildUrl (base);
172173 if (!params.empty ()) {
173174 url += " ?" + util::str (params);
@@ -183,8 +184,11 @@ std::string_view Session::getImpl(std::string_view base, std::string_view params
183184 return cache_->set (url, result);
184185}
185186
186- html::Html Session::getPageImpl (std::string_view base, std::string_view params) {
187- html::Html page (getImpl (base, params));
187+ std::pair<std::string_view, html::Html> Session::getImpl (
188+ std::string_view base,
189+ std::string_view params) {
190+ std::string_view raw = rawGetter (base, params);
191+ html::Html page (raw);
188192 html::Collection titles = page.tags (" title" );
189193 for (auto node : titles) {
190194 auto throwIfContains = [&](std::string_view s, auto dummy) {
@@ -198,7 +202,7 @@ html::Html Session::getPageImpl(std::string_view base, std::string_view params)
198202 throwIfContains (" []: Error: Invalid contest" , SessionError{" " });
199203 }
200204
201- return page;
205+ return {raw, std::move ( page)} ;
202206}
203207
204208} // namespace cacos::ejudge
0 commit comments