/**
 *
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for license information.
 *
 */

package com.microsoft.rest;

import com.squareup.okhttp.Headers;
import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User agent interceptor for putting a 'User-Agent' header in the request.
 */
public class CustomHeaderInterceptor implements Interceptor {
    private Map<String, List<String>> headers;

    /**
     * Initialize an instance of {@link UserAgentInterceptor} class with the default
     * 'User-Agent' header.
     */
    public CustomHeaderInterceptor() {
        headers = new HashMap<>();
    }

    public CustomHeaderInterceptor addHeader(String name, String value) {
        this.headers.put(name, Collections.singletonList(value));
        return this;
    }

    /**
     * Initialize an instance of {@link UserAgentInterceptor} class with the specified
     * 'User-Agent' header.
     *
     * @param headers the 'User-Agent' header value.
     */
    public CustomHeaderInterceptor addHeaders(Headers headers) {
        this.headers.putAll(headers.toMultimap());
        return this;
    }

    public CustomHeaderInterceptor addHeaderMap(Map<String, String> headers) {
        for (Map.Entry<String, String> header : headers.entrySet()) {
            this.headers.put(header.getKey(), Collections.singletonList(header.getValue()));
        }
        return this;
    }

    public CustomHeaderInterceptor addHeaderMultimap(Map<String, List<String>> headers) {
        this.headers.putAll(headers);
        return this;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request.Builder builder = chain.request().newBuilder();
        for (Map.Entry<String, List<String>> header : headers.entrySet()) {
            for (String value : header.getValue()) {
                builder = builder.addHeader(header.getKey(), value);
            }
        }
        return chain.proceed(builder.build());
    }
}

@@ -485,79 +485,81 @@
 %0A * 
-User agent interceptor for putting a 'User-Agent'
+An instance of this class enables adding custom
  header
+s
  in 
-the
+client
  request
 .%0A *
@@ -554,16 +554,92 @@
  request
+s%0A * when added to the %7B@link com.squareup.okhttp.OkHttpClient%7D interceptors
 .%0A */%0Apu
@@ -790,33 +790,36 @@
 e of %7B@link 
-UserAgent
+CustomHeader
 Interceptor%7D
@@ -828,52 +828,8 @@
 lass
- with the default%0A     * 'User-Agent' header
 .%0A  
@@ -907,32 +907,234 @@
 Map%3C%3E();%0A    %7D%0A%0A
+    /**%0A     * Add a single header key-value pair.%0A     *%0A     * @param name the name of the header.%0A     * @param value the value of the header.%0A     * @return the interceptor instance itself.%0A     */%0A
     public Custo
@@ -1304,174 +1304,162 @@
   * 
-Initialize an instance of %7B@link UserAgentInterceptor%7D class with the specified%0A     * 'User-Agent' header.%0A     *%0A     * @param headers the 'User-Agent' header value
+Add all headers in a %7B@link Headers%7D object.%0A     *%0A     * @param headers an OkHttp %7B@link Headers%7D object.%0A     * @return the interceptor instance itself
 .%0A  
@@ -1600,32 +1600,183 @@
 rn this;%0A    %7D%0A%0A
+    /**%0A     * Add all headers in a header map.%0A     *%0A     * @param headers a map of headers.%0A     * @return the interceptor instance itself.%0A     */%0A
     public Custo
@@ -2047,129 +2047,564 @@
     
-public CustomHeaderInterceptor addHeaderMultimap(Map%3CString, List%3CString%3E%3E headers) %7B%0A        this.headers.putAll(headers
+/**%0A     * Add all headers in a header multimap.%0A     *%0A     * @param headers a multimap of headers.%0A     * @return the interceptor instance itself.%0A     */%0A    public CustomHeaderInterceptor addHeaderMultimap(Map%3CString, List%3CString%3E%3E headers) %7B%0A        this.headers.putAll(headers);%0A        return this;%0A    %7D%0A%0A    /**%0A     * Remove a header.%0A     *%0A     * @param name the name of the header to remove.%0A     * @return the interceptor instance itself.%0A     */%0A    public CustomHeaderInterceptor removeHeader(String name) %7B%0A        this.headers.remove(name
 );%0A 

Add in-line comments for CustomHeaderInterceptor