add extra headers to upload event spec#5771
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR introduces support for configurable HTTP headers in upload endpoints through environment variables. The implementation adds a new environment variable REFLEX_UPLOAD_ENDPOINT_EXTRA_HEADERS that accepts colon-separated key-value pairs (format: key1:value1:key2:value2) for specifying additional headers.
The changes involve several key components:
- Environment Variable Support: Extended
interpret_env_var_valuefunction inenvironment.pyto handleMappingtypes, enabling parsing of key-value pairs from environment variables - Template-Based Upload Generation: Created a new
upload_js_templatefunction intemplates.pythat generates JavaScript code for file uploads with injected custom headers - Compiler Integration: Added compilation functions (
compile_upload_jsand_compile_upload_js) incompiler.pyto generate the upload.js file with environment-configured headers - Code Refactoring: Extracted the
uploadFilesfunction from the main state.js file into a separate helper module to support the new template-based approach - Path Management: Added
UPLOAD_PATHconstant andget_upload_js_path()utility function for consistent path handling
The architecture follows Reflex's established patterns where server-side configuration influences client-side behavior through code generation. During the compilation process, the environment variable is read and the specified headers are injected directly into the generated JavaScript upload code, ensuring they're always present when upload requests are made. This approach is particularly valuable for production deployments requiring authentication tokens, CORS headers, or integration with load balancers and proxies.
Confidence score: 3/5
- This PR introduces complex changes across multiple files with potential for integration issues
- Score reflects concerns about the mapping parsing logic and missing validation for malformed environment variable values
- Pay close attention to environment.py for the mapping interpretation logic and ensure comprehensive testing of the colon-separated format
7 files reviewed, no comments
CodSpeed Performance ReportMerging #5771 will not alter performanceComparing Summary
|
No description provided.