code: public static void addValueToHeader(Map<String, List<String>> headers,
              String key, String value, boolean singleValued) {
          List<String> values = headers.get(key);
  
          if (values == null) {
              values = new ArrayList<>(1);
              headers.put(key, values);
          }
  
          if (singleValued && values.size() == 1) {
              values.set(0, value);
          } else {
              values.add(value);
          }
      }
docs: Adds an header to the provided map of headers.
  
  @param headers the http headers map
  @param key the name of the new header to add
  @param value the value of the added header
  @param singleValued if true and the map already contains one value
  then it is replaced by the new value. Otherwise it simply adds a new
  value to this multi-valued header.