( self: HttpClientRequest.HttpClientRequest, security: S, credential: UnionToIntersection<HttpApiSecurity.HttpApiSecurity.Type<S>> )
| 5 | |
| 6 | /** @internal */ |
| 7 | export 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 | |
| 36 | const setCookie = (header: string | undefined, name: string, value: string): string => { |
| 37 | const pairs = (header ?? "").split(";").map((pair) => pair.trim()).filter((pair) => |
no test coverage detected