MCPcopy Create free account
hub / github.com/Effect-TS/effect / securityEncode

Function securityEncode

packages/effect/src/http-api/internal/securityEncode.ts:7–34  ·  view source on GitHub ↗
(
  self: HttpClientRequest.HttpClientRequest,
  security: S,
  credential: UnionToIntersection<HttpApiSecurity.HttpApiSecurity.Type<S>>
)

Source from the content-addressed store, hash-verified

5
6/** @internal */
7export const securityEncode = <S extends HttpApiSecurity.HttpApiSecurity>(
8 self: HttpClientRequest.HttpClientRequest,
9 security: S,
10 credential: UnionToIntersection<HttpApiSecurity.HttpApiSecurity.Type<S>>
11): HttpClientRequest.HttpClientRequest => {
12 switch (security._tag) {
13 case "Basic": {
14 const { password, username } = credential as HttpApiSecurity.Credentials
15 return HttpClientRequest.basicAuth(self, username, password)
16 }
17 case "Http":
18 return HttpClientRequest.setHeader(
19 self,
20 "authorization",
21 `${security.scheme} ${Redacted.value(credential as Redacted.Redacted)}`
22 )
23 case "ApiKey": {
24 const value = credential as Redacted.Redacted<string>
25 if (security.in === "header") return HttpClientRequest.setHeader(self, security.key, Redacted.value(value))
26 if (security.in === "query") return HttpClientRequest.setUrlParam(self, security.key, value)
27 return HttpClientRequest.setHeader(
28 self,
29 "cookie",
30 setCookie(self.headers.cookie, security.key, encodeURIComponent(Redacted.value(value)))
31 )
32 }
33 }
34}
35
36const setCookie = (header: string | undefined, name: string, value: string): string => {
37 const pairs = (header ?? "").split(";").map((pair) => pair.trim()).filter((pair) =>

Callers 1

layerClientSecurityFunction · 0.90

Calls 2

setCookieFunction · 0.85
valueMethod · 0.45

Tested by

no test coverage detected