Skip to content

Commit

Permalink
Disable SETTINGS_ENABLE_PUSH HTTP/2 setting (#741)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjcairo authored May 1, 2024
1 parent fb308ee commit a220837
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ struct HTTP2PushNotSupportedError: Error {}
struct HTTP2ReceivedGoAwayBeforeSettingsError: Error {}

final class HTTP2Connection {
internal static let defaultSettings = nioDefaultSettings + [HTTP2Setting(parameter: .enablePush, value: 0)]

let channel: Channel
let multiplexer: HTTP2StreamMultiplexer
let logger: Logger
Expand Down Expand Up @@ -196,7 +198,7 @@ final class HTTP2Connection {
// can be scheduled on this connection.
let sync = self.channel.pipeline.syncOperations

let http2Handler = NIOHTTP2Handler(mode: .client, initialSettings: nioDefaultSettings)
let http2Handler = NIOHTTP2Handler(mode: .client, initialSettings: Self.defaultSettings)
let idleHandler = HTTP2IdleHandler(delegate: self, logger: self.logger, maximumConnectionUses: self.maximumConnectionUses)

try sync.addHandler(http2Handler, position: .last)
Expand Down
23 changes: 23 additions & 0 deletions Tests/AsyncHTTPClientTests/HTTP2ConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import NIOConcurrencyHelpers
import NIOCore
import NIOEmbedded
import NIOHTTP1
import NIOHTTP2
import NIOPosix
import NIOSSL
import NIOTestUtils
Expand Down Expand Up @@ -338,6 +339,28 @@ class HTTP2ConnectionTests: XCTestCase {
}
XCTAssertLessThan(retryCount, maxRetries)
}

func testServerPushIsDisabled() {
let embedded = EmbeddedChannel()
let logger = Logger(label: "test.http2.connection")
let connection = HTTP2Connection(
channel: embedded,
connectionID: 0,
decompression: .disabled,
maximumConnectionUses: nil,
delegate: TestHTTP2ConnectionDelegate(),
logger: logger
)
_ = connection._start0()

let settingsFrame = HTTP2Frame(streamID: 0, payload: .settings(.settings([])))
XCTAssertNoThrow(try connection.channel.writeAndFlush(settingsFrame).wait())

let pushPromiseFrame = HTTP2Frame(streamID: 0, payload: .pushPromise(.init(pushedStreamID: 1, headers: [:])))
XCTAssertThrowsError(try connection.channel.writeAndFlush(pushPromiseFrame).wait()) { error in
XCTAssertNotNil(error as? NIOHTTP2Errors.PushInViolationOfSetting)
}
}
}

class TestConnectionCreator {
Expand Down
7 changes: 2 additions & 5 deletions Tests/AsyncHTTPClientTests/HTTPClientTestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//

import AsyncHTTPClient
@testable import AsyncHTTPClient
import Atomics
import Foundation
import Logging
Expand Down Expand Up @@ -361,10 +361,7 @@ internal final class HTTPBin<RequestHandler: ChannelInboundHandler> where
var httpSettings: HTTP2Settings {
switch self {
case .http1_1, .http2(_, _, nil), .refuse:
return [
HTTP2Setting(parameter: .maxConcurrentStreams, value: 10),
HTTP2Setting(parameter: .maxHeaderListSize, value: HPACKDecoder.defaultMaxHeaderListSize),
]
return HTTP2Connection.defaultSettings
case .http2(_, _, .some(let customSettings)):
return customSettings
}
Expand Down

0 comments on commit a220837

Please sign in to comment.