memos/server/router/api/v1
Steven 3d893a7394 fix(backend): implement protocol-agnostic header setting for dual gRPC/Connect-RPC support
Problem:
The codebase supports both native gRPC and Connect-RPC protocols, but auth
service was using grpc.SetHeader() which only works for native gRPC. This
caused "failed to set grpc header" errors when using Connect-RPC clients
(browsers using nice-grpc-web).

Solution:
- Created HeaderCarrier pattern for protocol-agnostic header setting
- HeaderCarrier stores headers in context for Connect-RPC requests
- Falls back to grpc.SetHeader for native gRPC requests
- Updated auth service to use SetResponseHeader() instead of grpc.SetHeader()
- Refactored Connect wrappers to use withHeaderCarrier() helper to eliminate
  code duplication

Additional fixes:
- Allow public methods when gRPC metadata is missing in ACL interceptor
- Properly handle ParseSessionCookieValue errors instead of ignoring them
- Fix buildSessionCookie to gracefully handle missing metadata

Files changed:
- server/router/api/v1/header_carrier.go: New protocol-agnostic header carrier
- server/router/api/v1/auth_service.go: Use SetResponseHeader, handle missing metadata
- server/router/api/v1/connect_services.go: Use withHeaderCarrier helper
- server/router/api/v1/acl.go: Allow public methods without metadata
- server/router/api/v1/connect_interceptors.go: Handle ParseSessionCookieValue errors

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-12 07:46:28 +08:00
..
test refactor: migrate to connect-rpc (#5338) 2025-12-11 19:49:07 +08:00
acl.go fix(backend): implement protocol-agnostic header setting for dual gRPC/Connect-RPC support 2025-12-12 07:46:28 +08:00
acl_config.go refactor: migrate to connect-rpc (#5338) 2025-12-11 19:49:07 +08:00
activity_service.go chore: fix linter 2025-10-31 08:36:12 +08:00
attachment_service.go chore: fix some typos in comments (#5332) 2025-12-11 07:50:16 +08:00
auth_service.go fix(backend): implement protocol-agnostic header setting for dual gRPC/Connect-RPC support 2025-12-12 07:46:28 +08:00
auth_service_client_info_test.go chore: fix linter 2025-08-31 20:22:32 +08:00
common.go refactor: remove unused constants 2025-10-16 20:40:46 +08:00
connect_handler.go refactor: migrate to connect-rpc (#5338) 2025-12-11 19:49:07 +08:00
connect_interceptors.go fix(backend): implement protocol-agnostic header setting for dual gRPC/Connect-RPC support 2025-12-12 07:46:28 +08:00
connect_services.go fix(backend): implement protocol-agnostic header setting for dual gRPC/Connect-RPC support 2025-12-12 07:46:28 +08:00
header_carrier.go fix(backend): implement protocol-agnostic header setting for dual gRPC/Connect-RPC support 2025-12-12 07:46:28 +08:00
health_service.go refactor(store): remove deprecated migration_history table and backward compatibility code 2025-12-01 22:54:30 +08:00
idp_service.go fix(security): add missing authorization checks to various services (#5217) 2025-11-06 19:42:44 +08:00
instance_service.go refactor: simplify theme/locale to user preferences and improve initialization 2025-12-02 09:08:46 +08:00
logger_interceptor.go chore: add a new LOG_STACKTRACES option (#4973) 2025-08-07 23:56:21 +08:00
memo_attachment_service.go fix(security): implement security review recommendations (#5228) 2025-11-06 23:32:27 +08:00
memo_relation_service.go fix(security): implement security review recommendations (#5228) 2025-11-06 23:32:27 +08:00
memo_service.go fix(api): implement custom memo ID support in CreateMemo (#5234) 2025-11-08 09:43:10 +08:00
memo_service_converter.go refactor: rename workspace to instance throughout codebase 2025-11-05 23:35:35 +08:00
memo_service_filter.go refactor: deprecate old filter 2025-07-22 21:25:57 +08:00
reaction_service.go fix(security): implement security review recommendations (#5228) 2025-11-06 23:32:27 +08:00
resource_name.go refactor: rename workspace to instance throughout codebase 2025-11-05 23:35:35 +08:00
shortcut_service.go refactor: remove unused constants 2025-10-16 20:40:46 +08:00
user_service.go refactor: migrate to connect-rpc (#5338) 2025-12-11 19:49:07 +08:00
user_service_stats.go fix: implement tag suggestions functionality 2025-11-08 09:15:38 +08:00
v1.go refactor: migrate to connect-rpc (#5338) 2025-12-11 19:49:07 +08:00