From 538b91fc6e24168c878db4341bd1e118a08851ae Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Tue, 23 Apr 2024 20:13:18 -0400 Subject: [PATCH] Remove renumbering indirection in settings frames This makes the code difficult to understand. --- .../src/main/kotlin/okhttp3/internal/http2/Http2Reader.kt | 6 +++--- .../src/main/kotlin/okhttp3/internal/http2/Http2Writer.kt | 8 +------- okhttp/src/main/kotlin/okhttp3/internal/http2/Settings.kt | 8 ++++---- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Reader.kt b/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Reader.kt index 38e7c685ba0a..cc8a4cc11486 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Reader.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Reader.kt @@ -261,7 +261,7 @@ class Http2Reader( if (length % 6 != 0) throw IOException("TYPE_SETTINGS length % 6 != 0: $length") val settings = Settings() for (i in 0 until length step 6) { - var id = source.readShort() and 0xffff + val id = source.readShort() and 0xffff val value = source.readInt() when (id) { @@ -277,11 +277,11 @@ class Http2Reader( } // SETTINGS_MAX_CONCURRENT_STREAMS - 3 -> id = 4 // Renumbered in draft 10. + 3 -> { + } // SETTINGS_INITIAL_WINDOW_SIZE 4 -> { - id = 7 // Renumbered in draft 10. if (value < 0) { throw IOException("PROTOCOL_ERROR SETTINGS_INITIAL_WINDOW_SIZE > 2^31 - 1") } diff --git a/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Writer.kt b/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Writer.kt index 6c63ef263300..ca8de63c9598 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Writer.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Writer.kt @@ -209,13 +209,7 @@ class Http2Writer( ) for (i in 0 until Settings.COUNT) { if (!settings.isSet(i)) continue - val id = - when (i) { - 4 -> 3 // SETTINGS_MAX_CONCURRENT_STREAMS renumbered. - 7 -> 4 // SETTINGS_INITIAL_WINDOW_SIZE renumbered. - else -> i - } - sink.writeShort(id) + sink.writeShort(i) sink.writeInt(settings[i]) } sink.flush() diff --git a/okhttp/src/main/kotlin/okhttp3/internal/http2/Settings.kt b/okhttp/src/main/kotlin/okhttp3/internal/http2/Settings.kt index ef704cdfde5d..a52bd3321037 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/http2/Settings.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/http2/Settings.kt @@ -116,7 +116,10 @@ class Settings { const val ENABLE_PUSH = 2 /** Sender's maximum number of concurrent streams. */ - const val MAX_CONCURRENT_STREAMS = 4 + const val MAX_CONCURRENT_STREAMS = 3 + + /** Window size in bytes. */ + const val INITIAL_WINDOW_SIZE = 4 /** HTTP/2: Size in bytes of the largest frame payload the sender will accept. */ const val MAX_FRAME_SIZE = 5 @@ -124,9 +127,6 @@ class Settings { /** HTTP/2: Advisory only. Size in bytes of the largest header list the sender will accept. */ const val MAX_HEADER_LIST_SIZE = 6 - /** Window size in bytes. */ - const val INITIAL_WINDOW_SIZE = 7 - /** Total number of settings. */ const val COUNT = 10 }