Skip to content

Disable SETTINGS_ENABLE_PUSH HTTP/2 setting #741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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