Skip to content

Conversation

@nadsella
Copy link
Contributor

This pull request introduces comprehensive support for HTTP header manipulation in the CRPC Request struct, enabling developers to read, set, add, and delete headers in a structured and case-insensitive manner. It also includes extensive documentation, tests, and examples to demonstrate the new functionality.

Core Enhancements to CRPC Header Handling:

  • Header Support in Request Struct:

    • Added a Header field of type http.Header to the Request struct for storing HTTP headers.
    • Updated the ServeHTTP method to populate the Header field from incoming HTTP requests.
  • New Header Manipulation Methods:

    • Introduced GetHeader, SetHeader, AddHeader, and DelHeader methods for accessing and modifying headers in a case-insensitive manner. These methods ensure nil safety and use Go's textproto.CanonicalMIMEHeaderKey for canonicalization.

Documentation and Examples:

  • Documentation:

    • Added CRPC Header Support documentation in HEADERS.md, detailing usage of the new header manipulation methods with examples.
  • Example Code:

    • Added an example in example_headers_test.go demonstrating how to read and manipulate headers in CRPC request handlers.

Testing:

  • Unit Tests:

    • Added unit tests for GetHeader, SetHeader, AddHeader, and DelHeader methods to validate their functionality, including edge cases like nil headers and case insensitivity.
  • Integration Tests:

    • Added integration tests to verify that headers are correctly passed from HTTP requests to CRPC handlers and that modifications to headers are reflected in the response.

@nadsella nadsella self-assigned this Jun 24, 2025
@nadsella nadsella requested a review from a team June 24, 2025 14:49
@nadsella nadsella marked this pull request as ready for review June 24, 2025 14:55
@nadsella nadsella added the enhancement New feature or request label Jun 25, 2025
// SetHeader sets the header entries associated with key to the
// single element value. It replaces any existing values
// associated with key. The key is case insensitive; it is
// canonicalized by textproto.CanonicalMIMEHeaderKey.
Copy link
Contributor

Choose a reason for hiding this comment

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

what does this refers to exactly?

Copy link
Contributor

@ei09010 ei09010 left a comment

Choose a reason for hiding this comment

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

looks nice :)

@nadsella nadsella merged commit e709548 into master Jul 3, 2025
3 checks passed
@nadsella nadsella deleted the crpc-headers branch July 3, 2025 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants