Vanillaxi opened a new pull request, #3443:
URL: https://github.com/apache/dubbo-go/pull/3443

   ## What is changed
   
   Fixes #3429.
   
   This PR exposes unary response headers and trailers for Triple generated 
clients through existing `client.CallOption`.
   
   Generated unary methods already accept `opts ...client.CallOption`, so users 
can now capture response metadata without changing generated method signatures:
   
   ```go
   var header, trailer http.Header
   
   resp, err := cli.Greet(
       ctx,
       req,
       client.WithResponseHeader(&header),
       client.WithResponseTrailer(&trailer),
   )
   ```
   
   Main changes:
   
   1. Add response metadata capture targets to `client.CallOptions`:
   
      - `ResponseHeader`
      - `ResponseTrailer`
   
   2. Add new call options:
   
      - `client.WithResponseHeader`
      - `client.WithResponseTrailer`
   
   3. Store response metadata capture targets in invocation attributes instead 
of attachments.
   
      These values are local client-side capture targets and should not be 
treated as RPC metadata to be transmitted.
   
   4. Pass the capture targets through the Triple unary invocation path.
   
   5. After the underlying Triple unary response is received, clone 
`triResp.Header()` and `triResp.Trailer()` into the user-provided targets.
   
   ## Why
   
   Dubbo-Go Triple runtime already supports unary response metadata through 
`triple_protocol.Response.Header()` and `triple_protocol.Response.Trailer()`.
   
   However, generated unary clients only return the business response message, 
so users could not access the underlying response headers and trailers from 
generated unary calls.
   
   Streaming generated clients already expose response metadata through 
`ResponseHeader()` and `ResponseTrailer()`. This PR closes the unary gap and 
helps complete the header/trailer usage pattern discussed in #2422.
   
   ## Compatibility
   
   Existing generated unary method signatures are unchanged.
   
   Users who do not need response metadata can continue using the existing API:
   
   ```go
   resp, err := cli.Greet(ctx, req)
   ```
   
   Users who need response metadata can opt in through call options:
   
   ```go
   var header, trailer http.Header
   
   resp, err := cli.Greet(
       ctx,
       req,
       client.WithResponseHeader(&header),
       client.WithResponseTrailer(&trailer),
   )
   ```
   
   This avoids adding extra generated methods such as `GreetWithResponse` and 
keeps the generated client API backward-compatible.
   
   ## Tests
   
   ```bash
   go test ./client
   go test ./protocol/triple
   ```
   
   The tests cover:
   
   - response header/trailer capture options being propagated through 
invocation attributes
   - Triple unary calls copying response headers/trailers back to user-provided 
variables
   - existing unary calls without response metadata options continuing to work
   
    


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to