Skip to content

Commit 976e884

Browse files
croakyiampogo
authored andcommitted
sdk/node: add User-Agent header
Use `sequence-sdk-node` instead of `chain-sdk-node`. Only add this header in Node environments. It is not allowed to be set in web browser environments. Closes #3366 Author: Dan Croak <dan@statusok.com> Date: Wed Apr 18 12:16:01 2018 -0700 upstream:b49d3dc86cda75ccf2005143a779a3e5c411b355
1 parent 0f154c5 commit 976e884

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

src/connection.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as uuid from 'uuid'
55

66
// some ugly business to get the right types for fetch while still polyfilling
77
const fetch: typeof window.fetch = require('fetch-ponyfill')().fetch
8+
const version: string = require('../package.json').version
89
import { readFileSync } from 'fs'
910
import { Agent } from 'https'
1011
import { errors } from './errors'
@@ -168,27 +169,26 @@ export class Connection {
168169
// processing.
169170
const snakeBody = snakeize(requestBody) // Ssssssssssss
170171

172+
headers = Object.assign(
173+
{
174+
Accept: 'application/json',
175+
'Content-Type': 'application/json',
176+
},
177+
headers
178+
)
179+
180+
// Node-only, User-Agent not allowed to be overriden in web browsers
181+
if (typeof window === 'undefined') {
182+
headers = Object.assign(
183+
{ 'User-Agent': 'sequence-sdk-node/' + version },
184+
headers
185+
)
186+
}
187+
171188
// TypeScript's DOM-based RequestInfo "type" doesn't have an "agent" prop
172189
const req: any = {
173190
method: 'POST',
174-
headers: Object.assign(
175-
{
176-
Accept: 'application/json',
177-
'Content-Type': 'application/json',
178-
179-
// TODO(jeffomatic): The Fetch API has inconsistent behavior between
180-
// browser implementations and polyfills.
181-
//
182-
// - For Edge: we can't use the browser's fetch API because it doesn't
183-
// always returns a WWW-Authenticate challenge to 401s.
184-
// - For Safari/Chrome: using fetch-ponyfill (the polyfill) causes
185-
// console warnings if the user agent string is provided.
186-
//
187-
// For now, let's not send the UA string.
188-
// 'User-Agent': 'chain-sdk-js/0.0'
189-
},
190-
headers
191-
),
191+
headers,
192192
body: JSON.stringify(snakeBody),
193193
}
194194

0 commit comments

Comments
 (0)