/** * Add a header with the specified name and value. Does validation of header names, allowing * non-ASCII values. */ public Builder addUnsafeNonAscii(String name, String value) { checkName(name); return addLenient(name, value); }
/** * Returns headers for the header names and values in the {@link Map}. */ public static Headers of(Map<String, String> headers) { if (headers == null) throw new NullPointerException("headers == null"); // Make a defensive copy and clean it up. String[] namesAndValues = new String[headers.size() * 2]; int i = 0; for (Map.Entry<String, String> header : headers.entrySet()) { if (header.getKey() == null || header.getValue() == null) { throw new IllegalArgumentException("Headers cannot be null"); } String name = header.getKey().trim(); String value = header.getValue().trim(); checkName(name); checkValue(value, name); namesAndValues[i] = name; namesAndValues[i + 1] = value; i += 2; } return new Headers(namesAndValues); }
/** * Add a header with the specified name and value. Does validation of header names and values. */ public Builder add(String name, String value) { checkName(name); checkValue(value, name); return addLenient(name, value); }
/** * Returns headers for the alternating header names and values. There must be an even number of * arguments, and they must alternate between header names and values. */ public static Headers of(String... namesAndValues) { if (namesAndValues == null) throw new NullPointerException("namesAndValues == null"); if (namesAndValues.length % 2 != 0) { throw new IllegalArgumentException("Expected alternating header names and values"); } // Make a defensive copy and clean it up. namesAndValues = namesAndValues.clone(); for (int i = 0; i < namesAndValues.length; i++) { if (namesAndValues[i] == null) throw new IllegalArgumentException("Headers cannot be null"); namesAndValues[i] = namesAndValues[i].trim(); } // Check for malformed headers. for (int i = 0; i < namesAndValues.length; i += 2) { String name = namesAndValues[i]; String value = namesAndValues[i + 1]; checkName(name); checkValue(value, name); } return new Headers(namesAndValues); }
/** * Add a header with the specified name and value. Does validation of header names, allowing * non-ASCII values. */ public Builder addUnsafeNonAscii(String name, String value) { checkName(name); return addLenient(name, value); }
/** * Set a field with the specified value. If the field is not found, it is added. If the field is * found, the existing values are replaced. */ public Builder set(String name, String value) { checkName(name); checkValue(value, name); removeAll(name); addLenient(name, value); return this; }
/** * Returns headers for the header names and values in the {@link Map}. */ public static Headers of(Map<String, String> headers) { if (headers == null) throw new NullPointerException("headers == null"); // Make a defensive copy and clean it up. String[] namesAndValues = new String[headers.size() * 2]; int i = 0; for (Map.Entry<String, String> header : headers.entrySet()) { if (header.getKey() == null || header.getValue() == null) { throw new IllegalArgumentException("Headers cannot be null"); } String name = header.getKey().trim(); String value = header.getValue().trim(); checkName(name); checkValue(value, name); namesAndValues[i] = name; namesAndValues[i + 1] = value; i += 2; } return new Headers(namesAndValues); }
/** * Add a header with the specified name and value. Does validation of header names and values. */ public Builder add(String name, String value) { checkName(name); checkValue(value, name); return addLenient(name, value); }
/** * Returns headers for the alternating header names and values. There must be an even number of * arguments, and they must alternate between header names and values. */ public static Headers of(String... namesAndValues) { if (namesAndValues == null) throw new NullPointerException("namesAndValues == null"); if (namesAndValues.length % 2 != 0) { throw new IllegalArgumentException("Expected alternating header names and values"); } // Make a defensive copy and clean it up. namesAndValues = namesAndValues.clone(); for (int i = 0; i < namesAndValues.length; i++) { if (namesAndValues[i] == null) throw new IllegalArgumentException("Headers cannot be null"); namesAndValues[i] = namesAndValues[i].trim(); } // Check for malformed headers. for (int i = 0; i < namesAndValues.length; i += 2) { String name = namesAndValues[i]; String value = namesAndValues[i + 1]; checkName(name); checkValue(value, name); } return new Headers(namesAndValues); }
/** * Set a field with the specified value. If the field is not found, it is added. If the field is * found, the existing values are replaced. */ public Builder set(String name, String value) { checkName(name); checkValue(value, name); removeAll(name); addLenient(name, value); return this; }
/** * Add a header with the specified name and value. Does validation of header names, allowing * non-ASCII values. */ public Builder addUnsafeNonAscii(String name, String value) { checkName(name); return addLenient(name, value); }
/** * Returns headers for the header names and values in the {@link Map}. */ public static Headers of(Map<String, String> headers) { if (headers == null) throw new NullPointerException("headers == null"); // Make a defensive copy and clean it up. String[] namesAndValues = new String[headers.size() * 2]; int i = 0; for (Map.Entry<String, String> header : headers.entrySet()) { if (header.getKey() == null || header.getValue() == null) { throw new IllegalArgumentException("Headers cannot be null"); } String name = header.getKey().trim(); String value = header.getValue().trim(); checkName(name); checkValue(value, name); namesAndValues[i] = name; namesAndValues[i + 1] = value; i += 2; } return new Headers(namesAndValues); }
/** * Add a header with the specified name and value. Does validation of header names and values. */ public Builder add(String name, String value) { checkName(name); checkValue(value, name); return addLenient(name, value); }
/** * Returns headers for the alternating header names and values. There must be an even number of * arguments, and they must alternate between header names and values. */ public static Headers of(String... namesAndValues) { if (namesAndValues == null) throw new NullPointerException("namesAndValues == null"); if (namesAndValues.length % 2 != 0) { throw new IllegalArgumentException("Expected alternating header names and values"); } // Make a defensive copy and clean it up. namesAndValues = namesAndValues.clone(); for (int i = 0; i < namesAndValues.length; i++) { if (namesAndValues[i] == null) throw new IllegalArgumentException("Headers cannot be null"); namesAndValues[i] = namesAndValues[i].trim(); } // Check for malformed headers. for (int i = 0; i < namesAndValues.length; i += 2) { String name = namesAndValues[i]; String value = namesAndValues[i + 1]; checkName(name); checkValue(value, name); } return new Headers(namesAndValues); }
/** * Set a field with the specified value. If the field is not found, it is added. If the field is * found, the existing values are replaced. */ public Builder set(String name, String value) { checkName(name); checkValue(value, name); removeAll(name); addLenient(name, value); return this; }