Alanxtl commented on issue #2422:
URL: https://github.com/apache/dubbo-go/issues/2422#issuecomment-4715307756

   按 #2422 里的几类能力看,现在 dubbo-go 基本已经有 API 了,但文档和一致性还没完全收口。
   
   **1. 客户端发送 request headers:已支持**
   
   两种方式都有:
   
   ```go
   ctx := triple.NewOutgoingContext(context.Background(), http.Header{
        "hello": []string{"triple"},
   })
   ctx = triple.AppendToOutgoingContext(ctx, "hello", "dubbo")
   ```
   
   Unary 调用会把 `ExtractFromOutgoingContext(ctx)` 合并到 
`request.Header()`;streaming client 也会在 `newConn` 时合并 outgoing context headers。
   
   **2. 服务端读取 request headers:已支持**
   
   所有 handler 类型都会调用:
   
   ```go
   ctx = newIncomingContext(ctx, conn.RequestHeader())
   ```
   
   用户可以:
   
   ```go
   headers, ok := triple.FromIncomingContext(ctx)
   ```
   
   另外,unary/server-stream 的 `Request` wrapper 里也有 `request.Header()`。
   
   **3. 服务端发送 response headers / trailers:已支持**
   
   有 context API:
   
   ```go
   triple.SetHeader(ctx, http.Header{"hi": []string{"triple"}})
   triple.SetTrailer(ctx, http.Header{"end": []string{"ok"}})
   triple.SendHeader(ctx, http.Header{"hi": []string{"triple"}})
   ```
   
   也有 response / stream wrapper API:
   
   ```go
   response.Header().Set("hi", "triple")
   response.Trailer().Set("end", "ok")
   
   stream.ResponseHeader().Set("hi", "triple")
   stream.ResponseTrailer().Set("end", "ok")
   ```
   
   **4. 客户端读取 unary response headers / trailers:已支持,#3428 补了文档**
   
   Unary 可以传 `Response` wrapper:
   
   ```go
   response := triple.NewResponse(&GreetResponse{})
   err := client.Greet(ctx, triple.NewRequest(&GreetRequest{}), response)
   
   headers := response.Header().Values("hi")
   trailers := response.Trailer().Values("end")
   ```
   
   #3428 主要是在这里补了注释说明。
   
   **5. 客户端读取 streaming response headers / trailers:也有 API**
   
   stream client wrapper 里有:
   
   ```go
   stream.ResponseHeader()
   stream.ResponseTrailer()
   ```
   
   例如 `ServerStreamForClient` / `BidiStreamForClient` 都有这两个方法。测试里也有覆盖 
`stream.ResponseHeader().Values(...)` / `stream.ResponseTrailer().Values(...)`。
   
   **还没完全收口的地方**
   
   - #2422 原 issue 里的 “client-side receiving headers and trailers” 当时还是 
`WIP`,#3428 只补了 unary response wrapper 注释,没有形成完整文档。
   - streaming 场景虽然 API 存在,但文档说明还比较散。
   - `SendHeader` 里现在看起来是 `mergeHeaders(conn.RequestHeader(), 
header)`,这块可能有历史设计或潜在问题。
   


-- 
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