Skip to content

Conversation

Jozott00
Copy link
Collaborator

Subsystem
gRPC

Problem Description
Before this, we had no support for passing gRPC metadata between the client and the server.

Solution
This PR solves this on JVM and Native by providing a custom interface (GrpcMetadata).

@Jozott00 Jozott00 self-assigned this Oct 21, 2025
@Jozott00 Jozott00 added the feature New feature or request label Oct 21, 2025
@Jozott00 Jozott00 marked this pull request as ready for review October 22, 2025 09:41
@Jozott00 Jozott00 requested a review from Mr3zee October 22, 2025 09:41
Copy link
Member

@Mr3zee Mr3zee left a comment

Choose a reason for hiding this comment

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

LGTM! Great work!
Couple of minor things below and a question:
Do you plan to add serializable versions of get/append/etc in a separate PR?

*
* @param key the name of the metadata entry to retrieve (case-insensitive). Must not end with `-bin`.
* @return the last value associated with the key, or `null` if no values exist
* @throws IllegalArgumentException if the key ends with `-bin`
Copy link
Member

Choose a reason for hiding this comment

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

Probably also when the key doesn't conform to this:

Keys must contain only the following ASCII characters:
 * - Digits: `0-9`
 * - Lowercase letters: `a-z` (uppercase letters are normalized to lowercase)
 * - Special characters: `-`, `_`, `.`

*
* ## Example usage
* ```kotlin
* val metadata = GrpcMetadata().apply {
Copy link
Member

Choose a reason for hiding this comment

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

Let's also add buildGrpcMetadata(body) method, which does the same as GrpcMetadata().apply { body() }

import libkgrpc.kgrpc_metadata_array_append
import kotlin.experimental.ExperimentalNativeApi

private value class GrpcKey private constructor(val name: String) {
Copy link
Member

Choose a reason for hiding this comment

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

Probably better to call it GrpcMetadataKey even if it is private

@InternalRpcApi
public actual typealias GrpcMetadata = io.grpc.Metadata

public actual operator fun GrpcMetadata.get(key: String): String? {
Copy link
Member

Choose a reason for hiding this comment

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

Does java lib perform ascii validation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants