-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interceptors.swift
31 lines (25 loc) · 1.02 KB
/
Interceptors.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import Foundation
import GRPC
// This is used in conjunction with GRPCServerLogger to append the remote address
// associated with the request to metadata in log messages.
final class ImageEmbosserServerInterceptorFactory: EmbosserServerInterceptorFactoryProtocol {
func makeEmbossImageInterceptors() -> [GRPC.ServerInterceptor<EmbossImageRequest, EmbossImageResponse>] {
return [ImageEmbosserServerInterceptor()]
}
}
final class ImageEmbosserServerInterceptor: ServerInterceptor<EmbossImageRequest, EmbossImageResponse> {
override func receive(
_ part: GRPCServerRequestPart<EmbossImageRequest>,
context: ServerInterceptorContext<EmbossImageRequest, EmbossImageResponse>
) {
switch part {
case .metadata(var m):
if context.remoteAddress != nil {
m.add(name: "remoteAddress", value: context.remoteAddress!.description)
}
context.receive(.metadata(m))
default:
context.receive(part)
}
}
}