diff --git a/okhttp/api/android/okhttp.api b/okhttp/api/android/okhttp.api index 91980d116b2f..3bc83fab92d8 100644 --- a/okhttp/api/android/okhttp.api +++ b/okhttp/api/android/okhttp.api @@ -595,6 +595,7 @@ public final class okhttp3/Headers : java/lang/Iterable, kotlin/jvm/internal/mar public static final field EMPTY Lokhttp3/Headers; public final fun -deprecated_size ()I public final fun byteCount ()J + public final fun combine (Lokhttp3/Headers;)Lokhttp3/Headers; public fun equals (Ljava/lang/Object;)Z public final fun get (Ljava/lang/String;)Ljava/lang/String; public final fun getDate (Ljava/lang/String;)Ljava/util/Date; @@ -623,6 +624,8 @@ public final class okhttp3/Headers$Builder { public final fun addUnsafeNonAscii (Ljava/lang/String;Ljava/lang/String;)Lokhttp3/Headers$Builder; public final fun build ()Lokhttp3/Headers; public final fun get (Ljava/lang/String;)Ljava/lang/String; + public final synthetic fun minusAssign (Ljava/lang/String;)V + public final synthetic fun plusAssign (Lokhttp3/Headers;)V public final fun removeAll (Ljava/lang/String;)Lokhttp3/Headers$Builder; public final fun set (Ljava/lang/String;Ljava/lang/String;)Lokhttp3/Headers$Builder; public final fun set (Ljava/lang/String;Ljava/time/Instant;)Lokhttp3/Headers$Builder; diff --git a/okhttp/api/jvm/okhttp.api b/okhttp/api/jvm/okhttp.api index 493b859afb9a..fe4b5698d635 100644 --- a/okhttp/api/jvm/okhttp.api +++ b/okhttp/api/jvm/okhttp.api @@ -595,6 +595,7 @@ public final class okhttp3/Headers : java/lang/Iterable, kotlin/jvm/internal/mar public static final field EMPTY Lokhttp3/Headers; public final fun -deprecated_size ()I public final fun byteCount ()J + public final fun combine (Lokhttp3/Headers;)Lokhttp3/Headers; public fun equals (Ljava/lang/Object;)Z public final fun get (Ljava/lang/String;)Ljava/lang/String; public final fun getDate (Ljava/lang/String;)Ljava/util/Date; @@ -623,6 +624,8 @@ public final class okhttp3/Headers$Builder { public final fun addUnsafeNonAscii (Ljava/lang/String;Ljava/lang/String;)Lokhttp3/Headers$Builder; public final fun build ()Lokhttp3/Headers; public final fun get (Ljava/lang/String;)Ljava/lang/String; + public final synthetic fun minusAssign (Ljava/lang/String;)V + public final synthetic fun plusAssign (Lokhttp3/Headers;)V public final fun removeAll (Ljava/lang/String;)Lokhttp3/Headers$Builder; public final fun set (Ljava/lang/String;Ljava/lang/String;)Lokhttp3/Headers$Builder; public final fun set (Ljava/lang/String;Ljava/time/Instant;)Lokhttp3/Headers$Builder; diff --git a/okhttp/src/commonJvmAndroid/kotlin/okhttp3/Headers.kt b/okhttp/src/commonJvmAndroid/kotlin/okhttp3/Headers.kt index 155aec37c584..3f9af8aeda96 100644 --- a/okhttp/src/commonJvmAndroid/kotlin/okhttp3/Headers.kt +++ b/okhttp/src/commonJvmAndroid/kotlin/okhttp3/Headers.kt @@ -134,6 +134,20 @@ class Headers internal constructor( fun newBuilder(): Builder = commonNewBuilder() + /** + * Returns a new headers instance that combines the headers of this instance with `other`. If + * this instance has no headers, then `other` is returned. If `other` has no headers, then this + * instance is returned. Otherwise, the headers of this instance followed by the headers of + * `other` are returned. + */ + @JvmName("combine") + operator fun plus(other: Headers): Headers = + when { + this.size == 0 -> other + other.size == 0 -> this + else -> Headers(this.namesAndValues + other.namesAndValues) + } + /** * Returns true if `other` is a `Headers` object with the same headers, with the same casing, in * the same order. Note that two headers instances may be *semantically* equal but not equal @@ -260,6 +274,11 @@ class Headers internal constructor( */ fun addAll(headers: Headers) = commonAddAll(headers) + @JvmSynthetic + operator fun plusAssign(headers: Headers) { + addAll(headers) + } + /** * Add a header with the specified name and formatted date. Does validation of header names and * value. @@ -306,6 +325,11 @@ class Headers internal constructor( fun removeAll(name: String) = commonRemoveAll(name) + @JvmSynthetic + operator fun minusAssign(name: String) { + removeAll(name) + } + /** * 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.