Skip to content

Commit

Permalink
fix(clientgen): fix setting user agent in ts client
Browse files Browse the repository at this point in the history
  • Loading branch information
rewop committed Feb 13, 2024
1 parent 7588ddc commit 838e87b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
8 changes: 7 additions & 1 deletion internal/clientgen/testdata/expected_baseauth_typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,14 @@ class BaseClient {
this.baseURL = baseURL
this.headers = {
"Content-Type": "application/json",
"User-Agent": "app-Generated-TS-Client (Encore/devel)",
}

// Add User-Agent header if the script is running in the server
// because browsers do not allow setting User-Agent headers to requests
if (typeof window === "undefined") {
this.headers["User-Agent"] = "app-Generated-TS-Client (Encore/devel)";
}

this.requestInit = options.requestInit ?? {};

// Setup what fetch function we'll be using in the base client
Expand Down
8 changes: 7 additions & 1 deletion internal/clientgen/testdata/expected_noauth_typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,14 @@ class BaseClient {
this.baseURL = baseURL
this.headers = {
"Content-Type": "application/json",
"User-Agent": "app-Generated-TS-Client (Encore/devel)",
}

// Add User-Agent header if the script is running in the server
// because browsers do not allow setting User-Agent headers to requests
if (typeof window === "undefined") {
this.headers["User-Agent"] = "app-Generated-TS-Client (Encore/devel)";
}

this.requestInit = options.requestInit ?? {};

// Setup what fetch function we'll be using in the base client
Expand Down
8 changes: 7 additions & 1 deletion internal/clientgen/testdata/expected_typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,14 @@ class BaseClient {
this.baseURL = baseURL
this.headers = {
"Content-Type": "application/json",
"User-Agent": "app-Generated-TS-Client (Encore/devel)",
}

// Add User-Agent header if the script is running in the server
// because browsers do not allow setting User-Agent headers to requests
if (typeof window === "undefined") {
this.headers["User-Agent"] = "app-Generated-TS-Client (Encore/devel)";
}

this.requestInit = options.requestInit ?? {};

// Setup what fetch function we'll be using in the base client
Expand Down
8 changes: 7 additions & 1 deletion internal/clientgen/typescript.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,14 @@ class BaseClient {
this.baseURL = baseURL
this.headers = {
"Content-Type": "application/json",
"User-Agent": "` + userAgent + `",
}
// Add User-Agent header if the script is running in the server
// because browsers do not allow setting User-Agent headers to requests
if (typeof window === "undefined") {
this.headers["User-Agent"] = "` + userAgent + `";
}
this.requestInit = options.requestInit ?? {};
// Setup what fetch function we'll be using in the base client
Expand Down

0 comments on commit 838e87b

Please sign in to comment.