http/internal/ClientLimits.protos

Repository
guillermomolina/protos
Commit
379c6fa63685c39a5954cfbd577bfda3b4df8e75
Tree
8cd4f4afe29ae4c3866381f38c1858108e9799f6
Blob
70753efc8c8a3c6020673e832c289c956b4737a3
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 limit capture of std:http/client (D218-B, HTTP.md §16.12). This
//! module is an unpublished implementation artifact, not an approved Standard
//! Library API. It is distinct from Limits, whose server limit names and
//! signed-64 range it does not share.

maxSigned32: 2147483647

limitNames: [
    "maxStatusLineBytes",
    "maxHeaderBytes",
    "maxHeaderFields",
    "maxChunkLineBytes",
    "maxTrailerBytes",
    "maxTrailerFields",
    "maxResponseBodyBytes",
    "maxInformationalResponses",
    "maxPrefetchBytes",
    "ioChunkBytes"
]

/// Validates limits (null or an ordinary object whose own slots are only
/// recognized limit names, each a positive Integer no greater than
/// 2147483647) and answers a private frozen snapshot of every effective
/// limit, or null when limits is not admissible. Inherited slots are never
/// read. facility is the private asynchronous bridge of std:http/Client.
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 > maxSigned32)) {
                                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 = {
            maxStatusLineBytes: pick("maxStatusLineBytes", 8192)
            maxHeaderBytes: pick("maxHeaderBytes", 32768)
            maxHeaderFields: pick("maxHeaderFields", 100)
            maxChunkLineBytes: pick("maxChunkLineBytes", 8192)
            maxTrailerBytes: pick("maxTrailerBytes", 8192)
            maxTrailerFields: pick("maxTrailerFields", 100)
            maxResponseBodyBytes: pick("maxResponseBodyBytes", 33554432)
            maxInformationalResponses: pick("maxInformationalResponses", 8)
            maxPrefetchBytes: pick("maxPrefetchBytes", 65536)
            ioChunkBytes: pick("ioChunkBytes", 16384)
        }
        captured.freeze()
    }
    captured
}