Chgen/view handle request context - #1321
Open
lemito wants to merge 12 commits into
Open
Conversation
View::Handle now receives server::request::RequestContext as the third parameter, giving handlers access to per-request data (e.g. user auth info set by the auth middleware). The dispatcher falls back to the legacy two-argument Handle via the ViewHasHandleWithContext concept, so existing hand-written views keep working unchanged.
…e signature Regenerate golden output with the three-argument Handle and migrate hand-written views in integration tests and the chaotic_openapi_service sample. The headersGet view demonstrates reading per-request context data (x-user-id) set by an auth checker.
lemito
marked this pull request as draft
August 14, 2026 21:58
segoon
suggested changes
Aug 16, 2026
| `main.py`. | ||
|
|
||
|
|
||
| ## View contract |
| Deps&& /*deps*/, | ||
| RequestContext& context | ||
| ) { | ||
| const auto& auth_info = USERVER_NAMESPACE::server::auth::GetUserAuthInfo(context); |
Collaborator
There was a problem hiding this comment.
можно прямо в chaotic_openapi_service записать в +1 ручку, отдельный сервис не требуется
| **Step 3.** Implement the generated view stub. Chaotic writes a skeleton to | ||
| `src/handlers/NAME/OPERATION/view.cpp` on the first run: | ||
| `src/handlers/NAME/OPERATION/view.cpp` on the first run. `Handle` always receives the | ||
| per-request context as the third argument (an alias `RequestContext` is provided in `View`): |
| * **View stub** — a minimal `.hpp`/`.cpp` pair in `SRC_DIR` that you fill in with business logic. | ||
| Existing view stubs are **never overwritten** on subsequent runs. | ||
| `View::Handle` receives the parsed request, the dependencies (`Deps`), and the per-request | ||
| `RequestContext` (see @ref scripts/docs/en/userver/chaotic_handlers.md "Authentication and request context" below). |
| "samples/benchmark_service/static_config.yaml":"taxi/uservices/userver/samples/benchmark_service/static_config.yaml", | ||
| "samples/benchmark_service/testsuite/conftest.py":"taxi/uservices/userver/samples/benchmark_service/testsuite/conftest.py", | ||
| "samples/benchmark_service/testsuite/test_benchmark.py":"taxi/uservices/userver/samples/benchmark_service/testsuite/test_benchmark.py", | ||
| "samples/chaotic_openapi_auth_service/CMakeLists.txt":"taxi/uservices/userver/samples/chaotic_openapi_auth_service/CMakeLists.txt", |
Collaborator
There was a problem hiding this comment.
не надо трогать этот файл)
| assert set(by_path) == {'testmepost/view.hpp', 'testmepost/view.cpp'} | ||
|
|
||
|
|
||
| def test_view_hpp_contract(): |
Collaborator
There was a problem hiding this comment.
тесты на посимвольное сравнение не требуются
lemito
marked this pull request as ready for review
August 17, 2026 08:16
segoon
reviewed
Aug 17, 2026
| const auto& auth_value = request.GetHeader(http::headers::kAuthorization); | ||
| constexpr std::string_view kBearerPrefix = "Bearer "; | ||
| if (auth_value.size() <= kBearerPrefix.size() || | ||
| std::string_view{auth_value}.substr(0, kBearerPrefix.size()) != kBearerPrefix) { |
|
|
||
| std::uint64_t user_id = 0; | ||
| try { | ||
| user_id = std::stoull(std::string{auth_value.substr(kBearerPrefix.size())}); |
| SetUserAuthInfo( | ||
| request_context, | ||
| server::auth::UserAuthInfo{ | ||
| server::auth::UserId{user_id}, |
Collaborator
There was a problem hiding this comment.
давай хотя бы из секдиста брать
или посмотри на другие примеры, откуда они токен/ключ берут
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add RequestContext for chaotic-openapi
Note: by creating a PR or an issue you automatically agree to the CLA. See CONTRIBUTING.md. Feel free to remove this note, the agreement holds.