1 package com.atlassian.marketplace.client.http;
2
3 import java.util.Map;
4
5 import com.google.common.collect.ImmutableMap;
6
7 /**
8 * Allows the caller to attach custom request headers to all client requests.
9 * @since 2.0.0
10 */
11 public interface RequestDecorator
12 {
13 /**
14 * Returns a map of header names and values that should be added to outgoing
15 * Marketplace requests.
16 */
17 public Map<String, String> getRequestHeaders();
18
19 public static abstract class Instances
20 {
21 /**
22 * Returns a {@link RequestDecorator} instance that always adds the same constant header values.
23 * @param headers a map of header names and values
24 */
25 public static RequestDecorator forHeaders(Map<String, String> headers)
26 {
27 final ImmutableMap<String, String> immutableHeaders = ImmutableMap.copyOf(headers);
28 return new RequestDecorator()
29 {
30 @Override
31 public Map<String,String> getRequestHeaders()
32 {
33 return immutableHeaders;
34 }
35 };
36 }
37 }
38 }