-
Notifications
You must be signed in to change notification settings - Fork 6k
fix(app) TypeError: Failed to execute 'set' on 'Headers': String contains non IS0-8859-1 code point. #7031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(app) TypeError: Failed to execute 'set' on 'Headers': String contains non IS0-8859-1 code point. #7031
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -246,7 +246,20 @@ export namespace Server { | |
| }, | ||
| ) | ||
| .use(async (c, next) => { | ||
| const directory = c.req.query("directory") || c.req.header("x-opencode-directory") || process.cwd() | ||
| const rawDirectory = c.req.query("directory") || c.req.header("x-opencode-directory") || process.cwd() | ||
| const directory = (() => { | ||
| const prefix = "opencode-uri:" | ||
|
Comment on lines
+250
to
+251
|
||
| if (!rawDirectory.startsWith(prefix)) return rawDirectory | ||
| try { | ||
| return decodeURIComponent(rawDirectory.slice(prefix.length)) | ||
| } catch (error) { | ||
| log.warn("Failed to decode opencode-uri directory, falling back to process.cwd()", { | ||
| rawDirectory, | ||
| error, | ||
| }) | ||
| return process.cwd() | ||
| } | ||
| })() | ||
| return Instance.provide({ | ||
| directory, | ||
| init: InstanceBootstrap, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ import { type Config } from "./gen/client/types.gen.js" | |
| import { OpencodeClient } from "./gen/sdk.gen.js" | ||
| export { type Config as OpencodeClientConfig, OpencodeClient } | ||
|
|
||
| const OPENCODE_DIRECTORY_HEADER_PREFIX = "opencode-uri:" | ||
|
|
||
| export function createOpencodeClient(config?: Config & { directory?: string }) { | ||
| if (!config?.fetch) { | ||
| const customFetch: any = (req: any) => { | ||
|
|
@@ -19,9 +21,22 @@ export function createOpencodeClient(config?: Config & { directory?: string }) { | |
| } | ||
|
|
||
| if (config?.directory) { | ||
| config.headers = { | ||
| ...config.headers, | ||
| "x-opencode-directory": config.directory, | ||
| const directoryHeader = OPENCODE_DIRECTORY_HEADER_PREFIX + encodeURIComponent(config.directory) | ||
| if (config.headers instanceof Headers || Array.isArray(config.headers)) { | ||
| const headers = new Headers(config.headers) | ||
| headers.set("x-opencode-directory", directoryHeader) | ||
| config = { | ||
| ...config, | ||
| headers, | ||
| } | ||
| } else { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style guide suggestion: The |
||
| config = { | ||
| ...config, | ||
| headers: { | ||
| ...(config.headers ?? {}), | ||
| "x-opencode-directory": directoryHeader, | ||
| }, | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ import { type Config } from "./gen/client/types.gen.js" | |
| import { OpencodeClient } from "./gen/sdk.gen.js" | ||
| export { type Config as OpencodeClientConfig, OpencodeClient } | ||
|
|
||
| const OPENCODE_DIRECTORY_HEADER_PREFIX = "opencode-uri:" | ||
|
|
||
| export function createOpencodeClient(config?: Config & { directory?: string }) { | ||
| if (!config?.fetch) { | ||
| const customFetch: any = (req: any) => { | ||
|
|
@@ -19,9 +21,22 @@ export function createOpencodeClient(config?: Config & { directory?: string }) { | |
| } | ||
|
|
||
| if (config?.directory) { | ||
| config.headers = { | ||
| ...config.headers, | ||
| "x-opencode-directory": config.directory, | ||
| const directoryHeader = OPENCODE_DIRECTORY_HEADER_PREFIX + encodeURIComponent(config.directory) | ||
| if (config.headers instanceof Headers || Array.isArray(config.headers)) { | ||
| const headers = new Headers(config.headers) | ||
| headers.set("x-opencode-directory", directoryHeader) | ||
| config = { | ||
| ...config, | ||
| headers, | ||
| } | ||
| } else { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style guide suggestion: The |
||
| config = { | ||
| ...config, | ||
| headers: { | ||
| ...(config.headers ?? {}), | ||
| "x-opencode-directory": directoryHeader, | ||
| }, | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The prefix constant is defined inline in the server code but as a constant in the SDK files. This creates a maintenance risk where the prefix strings could become out of sync. Consider extracting this to a shared constant or at minimum using a named constant here as well for consistency and easier maintenance.