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

refactor(proto): redefine HTTP headers structure #4

Merged
merged 3 commits into from
Nov 3, 2024

Conversation

madflojo
Copy link
Member

@madflojo madflojo commented Nov 3, 2024

This modifies the HTTP proto definition to allow headers with the same key but multiple values, which is evidently allowed in HTTP.

Summary by CodeRabbit

  • New Features

    • Enhanced HTTP header representation to support multiple values for each header.
    • Introduced a new Header message type for better handling of HTTP headers.
  • Bug Fixes

    • Improved accuracy of HTTP header handling in client requests and responses.

Because who doesn't love a little complexity?
@madflojo madflojo requested a review from Copilot November 3, 2024 15:10
Copy link
Contributor

coderabbitai bot commented Nov 3, 2024

Warning

Rate limit exceeded

@madflojo has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 22 minutes and 45 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 0264d93 and d00ea13.

Walkthrough

The pull request introduces significant changes to the sdk/http.proto file, specifically modifying the HTTPClient and HTTPClientResponse message structures. The headers field in both messages is updated from a simple map of string key-value pairs to a map where the values are of a new type, Header, allowing for multiple values per header. This change reflects a more accurate representation of HTTP headers. Additionally, a new Header message type is defined to accommodate this structure.

Changes

File Change Summary
sdk/http.proto - Updated headers field in HTTPClient from map<string, string> to map<string, Header>.
- Updated headers field in HTTPClientResponse from map<string, string> to map<string, Header>.
- Added new message type Header with a repeated field for value.

Possibly related PRs

  • Initial Protobuf files and repo goodies #1: The changes in http.proto within this PR introduce the HTTPClient and HTTPClientResponse message structures, which are directly related to the modifications made in the main PR regarding the headers field and the new Header message type.

Poem

In the meadow where headers bloom,
A rabbit hops with joy, not gloom.
With values stacked, so rich and bright,
HTTP's secrets now take flight!
A new Header hops along,
In our code, it sings a song! 🐇✨


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>, please review it.
    • Generate unit testing code 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 suggestion.

sdk/http.proto Outdated Show resolved Hide resolved
Co-authored-by: Copilot <[email protected]>
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.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
sdk/http.proto (3)

40-40: Document header value handling in responses

The change to support multiple header values is particularly important for responses, as common headers like Set-Cookie often have multiple values. Consider adding examples in the proto comments showing how to handle multi-valued headers.

  // Headers are the HTTP headers returned from the HTTP request.
+ // Example headers that commonly have multiple values:
+ // - Set-Cookie: Multiple cookies set in one response
+ // - Vary: Multiple cache variation headers
+ // - Access-Control-Allow-Headers: Multiple CORS headers
  map<string, Header> headers = 3;

47-55: Review field numbering in Header message

The value field uses number 2, suggesting field 1 might have been removed or is reserved. Consider either:

  1. Using field number 1 if no fields are reserved
  2. Adding a comment explaining why field 1 is skipped
  3. Adding explicit reserved fields if they're intended for future use
 message Header {
+  // Reserved for future use
+  reserved 1;
   // Value is the HTTP header value to include in requests and responses.
   // This field is a repeated field to allow for multiple values
   // which is allowed in HTTP headers.
   repeated string value = 2;
 }

Additionally, consider adding validation constraints in implementations to ensure header values follow RFC 7230 specifications.


Line range hint 1-55: Consider versioning strategy for breaking changes

The changes correctly implement HTTP header specifications but introduce breaking changes. Consider:

  1. Adding a version field to the package name (e.g., tarmac.http.v2)
  2. Providing migration guides in documentation
  3. Implementing client-side utilities to help convert between old and new formats
  4. Adding examples of common header patterns (e.g., authorization, content-type, accept)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between da705a0 and a697755.

📒 Files selected for processing (1)
  • sdk/http.proto (2 hunks)
🔇 Additional comments (1)
sdk/http.proto (1)

15-15: Breaking change: Verify client compatibility

The change from map<string, string> to map<string, Header> is a breaking change that will require updates to all clients using this proto definition. While this change correctly implements HTTP header specifications by supporting multiple values, it requires careful migration planning.

✅ Verification successful

Breaking change is well-documented and isolated

The change from map<string, string> to map<string, Header> is a breaking but necessary change that:

  1. Is properly documented with the new Header message type
  2. Correctly implements HTTP header specifications by supporting multiple values
  3. Is isolated to the HTTP protocol definitions only, with no direct dependencies in other proto files
  4. Has clear documentation in the proto file explaining the purpose of the change

The breaking change is acceptable as it's part of the core protocol definition and improves RFC compliance. The Header message type is well-defined with clear documentation about its purpose for supporting multiple values in HTTP headers.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Look for potential client implementations that need updating

# Search for HTTPClient usage in Go files
echo "Searching for Go implementations..."
rg -t go "HTTPClient.*headers" 

# Search for potential gRPC client implementations in other languages
echo "Searching for other client implementations..."
fd -e java -e py -e js -e ts | xargs rg "HTTPClient.*headers"

Length of output: 427


Script:

#!/bin/bash
# Let's first understand the structure of the codebase and look for any client implementations

# Find all proto files to understand the service structure
echo "Proto files in the repository:"
fd -e proto

# Look for any references to the http.proto file
echo -e "\nReferences to http.proto:"
rg -l "http\.proto"

# Search for any HTTP-related implementations
echo -e "\nHTTP-related implementations:"
rg -l -t go -t java -t python -t typescript -t javascript "http.*client"

# Look for build or generation configuration files that might indicate client usage
echo -e "\nBuild/generation config files:"
fd -e yaml -e yml -e json | grep -i "proto\|grpc\|build"

Length of output: 582


Script:

#!/bin/bash
# Let's check the README.md since it references http.proto and examine the actual proto files

# Check README.md content for context about client usage
echo "Checking README.md for client usage context:"
rg -A 5 -B 5 "http\.proto" README.md

# Check if the Header message type is already defined in http.proto
echo -e "\nChecking Header message definition:"
cat sdk/http.proto

# Check other proto files for dependencies on HTTPClient
echo -e "\nChecking other proto files for HTTPClient dependencies:"
rg "HTTPClient" sdk/*.proto

Length of output: 3070

Because even headers like to multiply sometimes.
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.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
sdk/http.proto (2)

15-15: LGTM! Consider adding header validation.

The change to support multiple values per header aligns with HTTP specifications. However, consider adding validation rules (either in implementation or documentation) for headers that typically expect single values (e.g., Content-Length, Host).


47-55: Enhance documentation with examples.

The Header message structure and comments are clear. Consider adding example usage in the comments to illustrate common scenarios:

 // Header is a structure used to define HTTP headers for HTTP requests.
 // As HTTP headers can have multiple values, this structure is used to define
 // the header values.
+//
+// Example usage:
+// Accept: ["text/html", "application/json"]
+// Set-Cookie: ["session=abc123", "theme=dark"]
 message Header {
   // Value is the HTTP header value to include in requests and responses.
   // This field is a repeated field to allow for multiple values
   // which is allowed in HTTP headers.
   repeated string value = 1;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a697755 and 0264d93.

📒 Files selected for processing (1)
  • sdk/http.proto (2 hunks)
🔇 Additional comments (2)
sdk/http.proto (2)

40-40: LGTM! Symmetric change for response headers.

The change maintains consistency with the request structure and correctly handles multiple values in response headers (e.g., Set-Cookie, Vary).


15-15: Verify impact of breaking changes.

The header structure changes are breaking changes that affect both requests and responses. Let's verify the impact across the codebase.

Also applies to: 40-40

@madflojo madflojo merged commit 3dac22a into tarmac-project:main Nov 3, 2024
2 checks passed
@madflojo madflojo deleted the src branch November 3, 2024 15:18
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.

1 participant