-
Notifications
You must be signed in to change notification settings - Fork 331
Expand file tree
/
Copy pathInferredProxyPropagator.java
More file actions
74 lines (66 loc) · 2.72 KB
/
InferredProxyPropagator.java
File metadata and controls
74 lines (66 loc) · 2.72 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package datadog.context.propagation;
import datadog.context.Context;
import datadog.context.InferredProxyContext;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
public class InferredProxyPropagator implements Propagator {
public static final String INFERRED_PROXY_KEY = "x-dd-proxy";
/**
* METHOD STUB: InferredProxy is currently not meant to be injected to downstream services Injects
* a context into a downstream service using the given carrier.
*
* @param context the context containing the values to be injected.
* @param carrier the instance that will receive the key/value pairs to propagate.
* @param setter the callback to set key/value pairs into the carrier.
*/
@Override
public <C> void inject(Context context, C carrier, CarrierSetter<C> setter) {}
/**
* Extracts a context from un upstream service.
*
* @param context the base context to store the extracted values on top, use {@link
* Context#root()} for a default base context.
* @param carrier the instance to fetch the propagated key/value pairs from.
* @param visitor the callback to walk over the carrier and extract its key/value pais.
* @return A context with the extracted values on top of the given base context.
*/
@Override
public <C> Context extract(Context context, C carrier, CarrierVisitor<C> visitor) {
if (context == null || carrier == null || visitor == null) {
return context;
}
InferredProxyContextExtractor extractor = new InferredProxyContextExtractor();
visitor.forEachKeyValue(carrier, extractor);
InferredProxyContext extractedContext = extractor.extractedContext;
if (extractedContext == null) {
return context;
}
return extractedContext.storeInto(context);
}
public static class InferredProxyContextExtractor implements BiConsumer<String, String> {
private InferredProxyContext extractedContext;
InferredProxyContextExtractor() {}
private Map<String, String> parseInferredProxyHeaders(String input) {
Map<String, String> parsedHeaders = new HashMap<>();
return parsedHeaders;
}
/**
* Performs this operation on the given arguments.
*
* @param key the first input argument from an http header
* @param value the second input argument from an http header
*/
@Override
public void accept(String key, String value) {
if (key == null || key.isEmpty() || !key.startsWith(INFERRED_PROXY_KEY)) {
return;
}
Map<String, String> inferredProxyMap = parseInferredProxyHeaders(value);
if (extractedContext == null) {
extractedContext = new InferredProxyContext();
}
extractedContext.putInferredProxyInfo(key, value);
}
}
}