-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow to pass custom headers to http-transport in niljs
- Loading branch information
Showing
5 changed files
with
50 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
function isValidHttpHeaders(headers: unknown) { | ||
if (headers === null || typeof headers !== "object" || Array.isArray(headers)) { | ||
throw new Error("Invalid headers provided to the RPC client."); | ||
} | ||
|
||
const isValidObj = Object.entries(headers).every( | ||
([key, value]) => | ||
typeof key === "string" && | ||
(typeof value === "string" || | ||
(Array.isArray(value) && value.every((v) => typeof v === "string"))), | ||
); | ||
|
||
if (!isValidObj) { | ||
throw new Error("Invalid http headers provided to the RPC client."); | ||
} | ||
} | ||
|
||
export { isValidHttpHeaders }; |