Skip to content

add extra headers to upload event spec#5771

Merged
adhami3310 merged 9 commits intomainfrom
khaleel/eng-7608-oss-optional-headers-for-upload-post
Sep 10, 2025
Merged

add extra headers to upload event spec#5771
adhami3310 merged 9 commits intomainfrom
khaleel/eng-7608-oss-optional-headers-for-upload-post

Conversation

@adhami3310
Copy link
Member

No description provided.

@linear
Copy link

linear bot commented Sep 9, 2025

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Environment Variable Support: Extended interpret_env_var_value function in environment.py to handle Mapping types, enabling parsing of key-value pairs from environment variables
  2. Template-Based Upload Generation: Created a new upload_js_template function in templates.py that generates JavaScript code for file uploads with injected custom headers
  3. Compiler Integration: Added compilation functions (compile_upload_js and _compile_upload_js) in compiler.py to generate the upload.js file with environment-configured headers
  4. Code Refactoring: Extracted the uploadFiles function from the main state.js file into a separate helper module to support the new template-based approach
  5. Path Management: Added UPLOAD_PATH constant and get_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

Edit Code Review Bot Settings | Greptile

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 9, 2025

CodSpeed Performance Report

Merging #5771 will not alter performance

Comparing khaleel/eng-7608-oss-optional-headers-for-upload-post (ca680db) with main (2e0e20f)

Summary

✅ 8 untouched benchmarks

@adhami3310 adhami3310 changed the title add extra headers to upload endpoint from environment variables add extra headers to upload event spec Sep 9, 2025
@adhami3310 adhami3310 merged commit a605e7a into main Sep 10, 2025
41 checks passed
@adhami3310 adhami3310 deleted the khaleel/eng-7608-oss-optional-headers-for-upload-post branch September 10, 2025 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants