http/internal/Limits.protos
- Repository
- guillermomolina/protos
- Commit
379c6fa63685c39a5954cfbd577bfda3b4df8e75- Tree
8cd4f4afe29ae4c3866381f38c1858108e9799f6- Blob
fde9a517946a3848220dc3cbbf2a30852e9442e4- Source
- View exact source on GitHub
// THE LICENSED WORK IS PROVIDED UNDER THE TERMS OF THE ADAPTIVE PUBLIC LICENSE
// ("LICENSE") AS FIRST COMPLETED BY: Guillermo Adrián Molina. ANY USE, PUBLIC
// DISPLAY, PUBLIC PERFORMANCE, REPRODUCTION OR DISTRIBUTION OF, OR PREPARATION OF
// DERIVATIVE WORKS BASED ON, THE LICENSED WORK CONSTITUTES RECIPIENT'S ACCEPTANCE
// OF THIS LICENSE AND ITS TERMS, WHETHER OR NOT SUCH RECIPIENT READS THE TERMS OF
// THE LICENSE. "LICENSED WORK" AND "RECIPIENT" ARE DEFINED IN THE LICENSE. A COPY
// OF THE LICENSE IS LOCATED IN THE TEXT FILE ENTITLED "LICENSE.TXT" ACCOMPANYING
// THE CONTENTS OF THIS FILE. IF A COPY OF THE LICENSE DOES NOT ACCOMPANY THIS
// FILE, A COPY OF THE LICENSE MAY ALSO BE OBTAINED AT THE FOLLOWING WEB SITE:
// https://github.com/guillermomolina/protos
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
// the specific language governing rights and limitations under the License.
//! Internal HTTP limit capture (HTTP.md §10) shared by std:http/server
//! admission and std:http/host construction (§15.2), so that both validate
//! one limits object by the same rule. This module is an unpublished
//! implementation artifact, not an approved Standard Library API.
maxSigned64: 9223372036854775807
limitNames: [
"maxRequestLineBytes",
"maxHeaderBytes",
"maxHeaderFields",
"maxChunkLineBytes",
"maxTrailerBytes",
"maxTrailerFields",
"maxRequestBodyBytes",
"maxPrefetchBytes",
"ioChunkBytes"
]
/// Validates limits and answers a private frozen snapshot of every effective
/// limit, or null when limits is not admissible. facility is the private
/// asynchronous bridge of the calling HTTP module.
capture: (facility, limits) => {
valid: true
if(limits !== null) {
valid = facility.ordinaryObject(limits)
if(valid) {
for(name in limits.slotNames()) {
if(valid) {
known: false
for(limitName in limitNames) {
if(name == limitName) {
known = true
}
}
if(known) {
value: limits.slotValue(name)
if(Integer.recognizes(value)) {
if((value <= 0) || (value > maxSigned64)) {
valid = false
}
} else {
valid = false
}
} else {
valid = false
}
}
}
}
}
pick: (name, fallback) => {
chosen: fallback
if((limits !== null) && limits.hasSlot(name)) {
chosen = limits.slotValue(name)
}
chosen
}
captured: null
if(valid) {
captured = {
maxRequestLineBytes: pick("maxRequestLineBytes", 8192)
maxHeaderBytes: pick("maxHeaderBytes", 32768)
maxHeaderFields: pick("maxHeaderFields", 100)
maxChunkLineBytes: pick("maxChunkLineBytes", 8192)
maxTrailerBytes: pick("maxTrailerBytes", 8192)
maxTrailerFields: pick("maxTrailerFields", 100)
maxRequestBodyBytes: pick("maxRequestBodyBytes", 33554432)
maxPrefetchBytes: pick("maxPrefetchBytes", 65536)
ioChunkBytes: pick("ioChunkBytes", 16384)
}
captured.freeze()
}
captured
}