Skip to content

Commit

Permalink
Remove renumbering indirection in settings frames (#8385)
Browse files Browse the repository at this point in the history
This makes the code difficult to understand.

Co-authored-by: Jesse Wilson <[email protected]>
Co-authored-by: Yuri Schimke <[email protected]>
  • Loading branch information
3 people authored Nov 19, 2024
1 parent 61ab31a commit 8da7440
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
6 changes: 3 additions & 3 deletions okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Reader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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")
}
Expand Down
8 changes: 1 addition & 7 deletions okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Writer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions okhttp/src/main/kotlin/okhttp3/internal/http2/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ 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

/** 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
}
Expand Down

0 comments on commit 8da7440

Please sign in to comment.