scoop:scoop.http:0.1.0
src/http2_options.scoop
Selected production source · src/http2_options.scoop
1
package scoop.http3
/**4
* Policy for an invalid received regular field; pseudo-field validation remains protocol-defined.5
*/6
public enum Http2InvalidRegularField {7
/**8
* Reports and ignores the invalid regular field.9
*/10
Ignore,11
/**12
* Rejects the stream carrying the invalid regular field.13
*/14
RejectStream }15
/**16
* Receive-only compatibility for field-edge whitespace and invalid regular fields; outgoing fields17
* remain strictly validated.18
*/19
public struct Http2ReceiveOptions(20
val allowFieldValueEdgeWhitespace: Boolean = false,21
val invalidRegularField: Http2InvalidRegularField = Http2InvalidRegularField.Ignore22
)24
/**25
* Positive local header, continuation, outgoing-header, and buffered-body limits. These are26
* distinct from advertised HTTP/2 SETTINGS.27
*/28
public struct Http2Limits(29
val headers: HttpHeaderLimits = HttpHeaderLimits(),30
val maxContinuations: Long = 8L,31
val maxSendHeaderBlockBytes: Long = 65536L,32
val maxPendingBodyBytes: Long = 65536L33
)35
/**36
* Values advertised to the peer for header tables, concurrent streams, stream windows, frame size,37
* and header-list size. Clients disable server push.38
*/39
public struct Http2Settings(40
val headerTableSize: UInt = 4096U,41
val maxConcurrentStreams: UInt = 100U,42
val initialWindowSize: UInt = 65535U,43
val maxFrameSize: UInt = 16384U,44
val maxHeaderListSize: UInt = 65536U45
)47
/**48
* One numeric HTTP/2 setting identifier and unsigned value.49
*/50
public struct Http2Setting(val id: UShort, val value: UInt)52
@CLayout internal struct NativeHttp2Config(53
val headerBytes: Long, val fieldBytes: Long, val fields: Long,54
val continuations: Long, val sendHeaderBytes: Long, val pendingBodyBytes: Long,55
val edgeWhitespace: Int, val rejectInvalid: Int56
)57
@CLayout internal struct NativeHttp2Settings(58
val tableSize: UInt, val concurrentStreams: UInt, val initialWindow: UInt,59
val frameSize: UInt, val headerSize: UInt60
)62
internal fun http2Config(options: Http2ReceiveOptions, limits: Http2Limits): NativeHttp2Config {63
requireHttpHeaderLimits(limits.headers)64
if (limits.maxContinuations <= 0L || limits.maxSendHeaderBlockBytes <= 0L || limits.maxPendingBodyBytes <= 0L)65
throw IllegalArgumentException(Some("HTTP/2 local limits must be positive"))66
return NativeHttp2Config(limits.headers.maxBytes, limits.headers.maxFieldBytes, limits.headers.maxFields,67
limits.maxContinuations, limits.maxSendHeaderBlockBytes, limits.maxPendingBodyBytes,68
if (options.allowFieldValueEdgeWhitespace) 1 else 0,69
if (options.invalidRegularField == Http2InvalidRegularField.RejectStream) 1 else 0)70
}72
internal fun http2Settings(settings: Http2Settings): NativeHttp2Settings {73
if (settings.initialWindowSize > 2147483647U || settings.maxFrameSize < 16384U || settings.maxFrameSize > 16777215U)74
throw IllegalArgumentException(Some("invalid HTTP/2 SETTINGS value"))75
return NativeHttp2Settings(settings.headerTableSize, settings.maxConcurrentStreams, settings.initialWindowSize,76
settings.maxFrameSize, settings.maxHeaderListSize)77
}