-
Notifications
You must be signed in to change notification settings - Fork 409
fix core: storing all cookies without possibly wrong selection, keeping session cookies semantics #1292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alex-aparin
wants to merge
30
commits into
userver-framework:develop
Choose a base branch
from
alex-aparin:cookies_fix
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix core: storing all cookies without possibly wrong selection, keeping session cookies semantics #1292
Changes from 24 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
662cb13
Fixed storing of cookies at http client's response side (without jar …
alex-aparin 240c8ad
Reverted changes, which break API of cookies
alex-aparin 8a6ef54
CookieJar was added to response of http client (with backward compati…
alex-aparin d051cc6
Data structure for CookieJar's storage was simplified
alex-aparin 6684fc7
Storage cookies was optimized, list was removed by smallvector
alex-aparin 42a33d3
Storage of validated cookies was refactored, extra field were removed…
alex-aparin f834188
Rough implementations for GetCookies/GetAnyCookie were added.
alex-aparin d7a4543
Runtime error for unitests was fixed.
alex-aparin 28e828c
Tests and bugs related with domain checks were fixed
alex-aparin 3ada078
Bug in path's prefix matching was fixed. All tests related with cooki…
alex-aparin a77df26
Support for merging two cookie jars was added
alex-aparin 496bd61
Computation default-path was fixed with test. Supercookie test was added
alex-aparin 0d958ff
Security tests were added. API was simplified. Fixed bugs for sorting…
alex-aparin d44acd5
Setter of cookie jar for request was added
alex-aparin edc6757
Fixed error for usage empty response for cookie jar. Storage was refa…
alex-aparin 701abff
Additional tests for covering unicode and security attributes were ad…
alex-aparin 4be2566
Verbosity of tests were reduced via additional fixture
alex-aparin 794ceda
Extra allocations were reduced within implementation of CookieJar
alex-aparin 8820df6
PathMatch algorithm was simplified and followed strictly for standard…
alex-aparin c244815
Initial version of enabling internal libcurl cookies engine was added
alex-aparin bfc1ec9
Tests were adapted to use libcurl embedded cookies engine
alex-aparin e1268b2
FindCookieValue method was implemented
alex-aparin c959fcf
Resolved conflict with ca04d21 commit
alex-aparin a67de9c
Merge branch 'develop' into cookies_fix
alex-aparin af3b7ec
Inproperly merged ParseSingleCookie method was fixed
alex-aparin 6761cf2
Support for "punification" was added
alex-aparin 9d40b60
UnicodeUrls test was enabled with some nuanсes
alex-aparin cb0764b
Refactoring of tests. Minor fix for client_test CookiesMap, major tes…
alex-aparin 6fa8a9a
Fragile constructor of CookieJar was made private. Additional tests f…
alex-aparin afbbbb0
Workaround about blocked fs operations of psl was added
alex-aparin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #pragma once | ||
|
|
||
| /// @file userver/clients/http/cookie_jar.hpp | ||
| /// @brief @copybrief clients::http::CookieJar | ||
| #include <string> | ||
| #include <vector> | ||
| #include <optional> | ||
|
|
||
| USERVER_NAMESPACE_BEGIN | ||
|
|
||
| namespace clients::http { | ||
|
|
||
| class Request; | ||
|
|
||
| /// @brief Storage for cookies, compliable with RFC 6265. Can be used for sending and receiving cookies on agent side. | ||
| class CookieJar final { | ||
| public: | ||
| CookieJar(); | ||
| CookieJar(std::vector<std::string>&& cookies); | ||
| ~CookieJar(); | ||
| CookieJar(const CookieJar&); | ||
| CookieJar(CookieJar&&); | ||
| CookieJar& operator=(const CookieJar&); | ||
| CookieJar& operator=(CookieJar&&); | ||
|
|
||
| /// @brief Gets ANY cookie value, associated with name. In general case, multiple cookies can be stored with the same name, order is not specified | ||
| /// @param name Name of cookie | ||
| /// @return Cookie's value | ||
| /// @warning This method has lineral complexity | ||
| std::optional<std::string> FindCookieValue(std::string_view name); | ||
| private: | ||
| friend class Request; | ||
| std::vector<std::string> cookies_; | ||
| }; | ||
|
|
||
| } // namespace clients::http | ||
|
|
||
| USERVER_NAMESPACE_END | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,4 +79,4 @@ class Response final { | |
|
|
||
| } // namespace clients::http | ||
|
|
||
| USERVER_NAMESPACE_END | ||
| USERVER_NAMESPACE_END | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #include <userver/clients/http/cookie_jar.hpp> | ||
|
|
||
| #include <chrono> | ||
| #include <cstddef> | ||
| #include <string> | ||
| #include <string_view> | ||
| #include <set> | ||
| #include <utility> | ||
| #include <vector> | ||
| #include <algorithm> | ||
| #include <boost/container/small_vector.hpp> | ||
|
|
||
| #include <userver/utils/datetime.hpp> | ||
| #include <userver/utils/str_icase.hpp> | ||
| #include <userver/logging/log.hpp> | ||
| #include <userver/http/url.hpp> | ||
|
|
||
| USERVER_NAMESPACE_BEGIN | ||
|
|
||
| namespace clients::http { | ||
|
|
||
| CookieJar::CookieJar() = default; | ||
| CookieJar::~CookieJar() = default; | ||
| CookieJar::CookieJar(std::vector<std::string>&& cookies) : | ||
| cookies_(std::move(cookies)) { | ||
|
|
||
| } | ||
| CookieJar::CookieJar(const CookieJar&) = default; | ||
| CookieJar::CookieJar(CookieJar&&) = default; | ||
| CookieJar& CookieJar::operator=(const CookieJar&) = default; | ||
| CookieJar& CookieJar::operator=(CookieJar&&) = default; | ||
|
|
||
| std::optional<std::string> CookieJar::FindCookieValue(std::string_view name) { | ||
| // TODO: not optimal way to search | ||
| for (std::string_view line : cookies_) { | ||
| while (!line.empty() && (line.back() == '\n' || line.back() == '\r')) { | ||
| line.remove_suffix(1); | ||
| } | ||
|
|
||
| const auto value_pos = line.rfind('\t'); | ||
| if (value_pos == std::string_view::npos || value_pos == 0) { | ||
| // A comment or a malformed line, both have nothing to look at. | ||
| continue; | ||
| } | ||
| const auto name_pos = line.rfind('\t', value_pos - 1); | ||
| if (name_pos == std::string_view::npos) { | ||
| continue; | ||
| } | ||
|
|
||
| // Cookie names are case-sensitive, RFC 6265, section 5.3. | ||
| if (line.substr(name_pos + 1, value_pos - name_pos - 1) == name) { | ||
| return std::string{line.substr(value_pos + 1)}; | ||
| } | ||
| } | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| } // namespace clients::http | ||
|
|
||
| USERVER_NAMESPACE_END |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.