AWS Signature V4 要求的 URI 编码,仅保留 A-Za-z0-9_-.~ 不编码
(str: string, encodeSlash: boolean = true)
| 57 | |
| 58 | /** AWS Signature V4 要求的 URI 编码,仅保留 A-Za-z0-9_-.~ 不编码 */ |
| 59 | function awsUriEncode(str: string, encodeSlash: boolean = true): string { |
| 60 | let result = ""; |
| 61 | const bytes = new TextEncoder().encode(str); |
| 62 | for (const b of bytes) { |
| 63 | const ch = String.fromCharCode(b); |
| 64 | if ( |
| 65 | (ch >= "A" && ch <= "Z") || |
| 66 | (ch >= "a" && ch <= "z") || |
| 67 | (ch >= "0" && ch <= "9") || |
| 68 | ch === "_" || |
| 69 | ch === "-" || |
| 70 | ch === "~" || |
| 71 | ch === "." |
| 72 | ) { |
| 73 | result += ch; |
| 74 | } else if (ch === "/" && !encodeSlash) { |
| 75 | result += ch; |
| 76 | } else { |
| 77 | result += `%${b.toString(16).toUpperCase().padStart(2, "0")}`; |
| 78 | } |
| 79 | } |
| 80 | return result; |
| 81 | } |
| 82 | |
| 83 | // ---- S3 错误处理 ---- |
| 84 |
no outgoing calls
no test coverage detected