Skip to content
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

feat: support experimental headers #1425

Conversation

ologbonowiwi
Copy link
Contributor

@ologbonowiwi ologbonowiwi commented Mar 14, 2024

  • test: create test for experimental header
  • feat: implement experimental headers handling

Issue Reference(s):
Fixes #1413
/claim #1413
Doc PR: tailcallhq/tailcallhq.github.io#157

Build & Testing:

  • I ran cargo test successfully.
  • I have run ./lint.sh --mode=fix to fix all linting issues raised by ./lint.sh --mode=check.

Checklist:

  • I have added relevant unit & integration tests.
  • I have updated the documentation accordingly.
  • I have performed a self-review of my code.
  • PR follows the naming convention of <type>(<optional scope>): <title>

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Enhanced response flexibility by introducing support for experimental headers.
  • Enhancements
    • Streamlined management and retrieval of experimental headers for easier feature experimentation.
  • Tests
    • Ensured reliability and stability through the implementation of tests for experimental headers functionality.

Copy link
Contributor

coderabbitai bot commented Mar 14, 2024

Walkthrough

The recent changes introduce support for experimental headers in HTTP responses, enabling the use of custom X-* headers for experimental features. These changes span across various components like schema definition, server configuration, and request handling, ensuring that specified experimental headers are appropriately processed and included in the server's responses.

Changes

Files Change Summaries
generated/.../.tailcallrc.graphql
generated/.../.tailcallrc.schema.json
Added experimental field to allow X-Something headers.
src/blueprint/server.rs
src/config/headers.rs
src/http/request_context.rs
benches/impl_path_string_for_evaluation_context.rs
Introduced experimental_headers field and methods for handling experimental headers.
src/config/server.rs
src/http/request_handler.rs
Enhanced server and request handling to support X-* experimental headers.
tests/execution/experimental-headers.md Added tests for experimental headers functionality.

Assessment against linked issues

Objective Addressed Explanation
Add support for experimental headers (#1413)

Poem

In the land of code, where the bits roam free,
A rabbit hopped forth, full of glee.
"Let's add," it said, "with a leap and a twirl,
Headers experimental, to give them a whirl!"
🐰🌟
With a click and a clack, in the server's embrace,
Now custom headers find their rightful place.
"A job well done!" the rabbit beams,
In the digital meadow of developers' dreams.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@github-actions github-actions bot added the type: feature Brand new functionality, features, pages, workflows, endpoints, etc. label Mar 14, 2024
Copy link

codecov bot commented Mar 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.58%. Comparing base (9003853) to head (ec3f5aa).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1425      +/-   ##
==========================================
+ Coverage   88.55%   88.58%   +0.02%     
==========================================
  Files         127      127              
  Lines       13604    13634      +30     
==========================================
+ Hits        12047    12077      +30     
  Misses       1557     1557              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f4b9e21 and f55abf7.
Files ignored due to path filters (3)
  • tests/snapshots/execution_spec__experimental-headers.md_assert_0.snap is excluded by: !**/*.snap
  • tests/snapshots/execution_spec__experimental-headers.md_client.snap is excluded by: !**/*.snap
  • tests/snapshots/execution_spec__experimental-headers.md_merged.snap is excluded by: !**/*.snap
Files selected for processing (8)
  • generated/.tailcallrc.graphql (1 hunks)
  • generated/.tailcallrc.schema.json (1 hunks)
  • src/blueprint/server.rs (4 hunks)
  • src/config/headers.rs (1 hunks)
  • src/config/server.rs (1 hunks)
  • src/http/request_context.rs (3 hunks)
  • src/http/request_handler.rs (4 hunks)
  • tests/execution/experimental-headers.md (1 hunks)
Check Runs (1)
codecov/patch completed (2)
  • src/http/request_handler.rs: 169-169: Added line #L169 was not covered by tests
  • src/http/request_handler.rs: 172-172: Added line #L172 was not covered by tests
Additional comments: 11
tests/execution/experimental-headers.md (1)
  • 1-44: The documentation provides a clear example of how to define and test experimental headers using GraphQL schema and mock requests. It's well-structured and aligns with the PR's objectives of supporting x-* headers.
src/config/headers.rs (1)
  • 21-24: The addition of the experimental field to the Headers struct is well-implemented. It allows for the inclusion of experimental headers in server responses, aligning with the PR's objectives. The use of Option<Vec<String>> is appropriate for optional and multiple values.
src/http/request_context.rs (3)
  • 22-22: The introduction of the experimental_headers field to the RequestContext struct is correctly implemented. This field is essential for handling experimental headers throughout the request lifecycle.
  • 101-101: Initialization of the experimental_headers field with HeaderMap::new() in the From<&AppContext> implementation is correct, ensuring that each request context starts with an empty set of experimental headers.
  • 132-132: Similarly, initializing the experimental_headers field in the test module's default RequestContext is appropriate, ensuring consistency in test environments.
src/blueprint/server.rs (2)
  • 33-33: Adding the experimental_headers field to the Server struct is a crucial step in supporting experimental headers. This field allows specifying which headers are considered experimental at the server level.
  • 75-77: The get_experimental_headers method correctly converts the experimental_headers vector into a BTreeSet<String> for efficient access and deduplication. This method facilitates the retrieval of experimental headers in a structured manner.
src/config/server.rs (1)
  • 175-180: The get_experimental_headers method is implemented correctly, providing a way to retrieve experimental headers defined in the server configuration. This method ensures that experimental headers can be accessed and utilized where needed.
src/http/request_handler.rs (2)
  • 71-77: The creation of allowed headers, including experimental headers, is correctly implemented. This step is crucial for filtering and including only the allowed and experimental headers in the request context.
  • 93-103: The update_experimental_headers function correctly updates the response headers with the experimental headers from the request context. This implementation ensures that experimental headers are correctly forwarded in the server's response.
generated/.tailcallrc.graphql (1)
  • 580-584: The addition of the experimental field to the Headers input type is correctly implemented and documented. It aligns with the PR's objective to support experimental headers.

Please ensure the application correctly processes these headers and includes them in responses as intended.

generated/.tailcallrc.schema.json Outdated Show resolved Hide resolved
src/http/request_handler.rs Show resolved Hide resolved
src/http/request_handler.rs Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f55abf7 and 0f0a7bc.
Files selected for processing (1)
  • tests/execution/experimental-headers.md (1 hunks)
Additional comments: 3
tests/execution/experimental-headers.md (3)
  • 3-15: The GraphQL schema definition correctly implements the functionality for handling experimental headers as outlined in the PR objectives. This is a well-structured approach to extending the server's capabilities.
  • 18-32: The mock YAML configuration correctly demonstrates the inclusion of experimental headers in a request. However, the presence of x-not-allowed header raises questions about its purpose in this context. Is it intended to test the server's behavior with unsupported headers? Clarification would be helpful.
  • 34-42: The YAML configuration for the assertion correctly tests the server's handling of experimental headers in a GraphQL request. This aligns with the PR objectives and demonstrates the desired functionality effectively.

ologbonowiwi and others added 3 commits March 14, 2024 00:42
# Conflicts:
#	benches/impl_path_string_for_evaluation_context.rs
#	generated/.tailcallrc.graphql
#	generated/.tailcallrc.schema.json
#	src/config/headers.rs
#	src/http/request_context.rs
#	src/http/request_handler.rs
@tusharmath tusharmath enabled auto-merge (squash) March 14, 2024 06:53
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0f0a7bc and ec3f5aa.
Files ignored due to path filters (1)
  • tests/snapshots/execution_spec__experimental-headers.md_merged.snap is excluded by: !**/*.snap
Files selected for processing (8)
  • benches/impl_path_string_for_evaluation_context.rs (1 hunks)
  • generated/.tailcallrc.graphql (1 hunks)
  • generated/.tailcallrc.schema.json (1 hunks)
  • src/blueprint/server.rs (4 hunks)
  • src/config/headers.rs (2 hunks)
  • src/config/server.rs (2 hunks)
  • src/http/request_context.rs (3 hunks)
  • src/http/request_handler.rs (4 hunks)
Files skipped from review as they are similar to previous changes (7)
  • generated/.tailcallrc.graphql
  • generated/.tailcallrc.schema.json
  • src/blueprint/server.rs
  • src/config/headers.rs
  • src/config/server.rs
  • src/http/request_context.rs
  • src/http/request_handler.rs
Additional comments: 1
benches/impl_path_string_for_evaluation_context.rs (1)
  • 250-250: The addition of experimental_headers to RequestContext aligns with the PR's objectives. Ensure that this new field is utilized effectively in processing and including x-* headers in API responses.
Verification successful

The verification process has confirmed that the experimental_headers field is correctly added, initialized, and utilized across the application for handling HTTP requests and responses, aligning with the PR's objectives. The usage and configuration of this field are consistent with the intended purpose of managing experimental headers effectively.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that `experimental_headers` is used in HTTP request and response handling.
rg --type rust 'experimental_headers'

Length of output: 1518

@tusharmath tusharmath merged commit 382a854 into tailcallhq:main Mar 14, 2024
21 checks passed
@tusharmath
Copy link
Contributor

Realized after merging that we need a test to make sure

  1. only x- headers are added and not any other header
  2. the headers filtration is case-insensitive

@ologbonowiwi ologbonowiwi deleted the feat/#1413/support-experimental-headers branch March 14, 2024 10:58
ssddOnTop pushed a commit that referenced this pull request Mar 16, 2024
Co-authored-by: Tushar Mathur <tusharmath@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 Bounty claim type: feature Brand new functionality, features, pages, workflows, endpoints, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add support for experimental headers
2 participants