nsmcp::CodeUpstreamTool method get (protected)

 <instance of nsmcp::CodeUpstreamTool[i]> get endpoint accept

Defined in /usr/local/ns/tcl/nsmcp/code-upstream.tcl

Parameters:
endpoint (required)
accept (required)

Testcases:
No testcase defined.
Source code:
if {![regexp {^/repos/[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+/(commits|contents)(/|\?)} $endpoint] || [regexp {[\r\n]} $endpoint]} {error "invalid-github-endpoint"}
if {[incr :requests]>5} {error "upstream-request-limit"}
set url https://api.github.com$endpoint
# Small successful-response cache, server-local and size bounded.
set cache nsmcp:upstream-cache:[ns_info server]
set key [ns_crypto::md string -digest sha256 -- [list $url $accept]]
if {[nsv_exists $cache $key]} {
    set cached [nsv_get $cache $key]
    if {[clock seconds]-[dict get $cached at]<60} {return [dict get $cached body]}
}
if {[catch {:http $url $accept} reply]} {error "github-transport-failed"}
set status [dict get $reply status]
if {$status!=200} {error "github-http-$status"}
set body [dict get $reply body]
if {[string bytelength $body]>1048576} {error "github-response-too-large"}
if {[llength [nsv_array names $cache]]>=16} {nsv_unset -nocomplain $cache}
nsv_set $cache $key [dict create at [clock seconds] body $body]
return $body
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: