Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
fix: setting x-readme-api-explorer instead of a custom UA (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
erunion authored Feb 9, 2020
1 parent fa67fdc commit 4100911
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/api-explorer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/api-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@readme/syntax-highlighter": "^4.16.0",
"@readme/variable": "^4.16.0",
"classnames": "^2.2.5",
"fetch-har": "^2.2.0",
"fetch-har": "^2.2.1",
"httpsnippet": "^1.19.1",
"js-cookie": "^2.1.4",
"lodash.kebabcase": "^4.1.1",
Expand Down
13 changes: 11 additions & 2 deletions packages/api-explorer/src/Doc.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const React = require('react');
const PropTypes = require('prop-types');
const fetchHar = require('fetch-har');
const { constructRequest } = require('fetch-har');
const extensions = require('@readme/oas-extensions');
const markdown = require('@readme/markdown');
const Waypoint = require('react-waypoint');
Expand Down Expand Up @@ -72,7 +72,16 @@ class Doc extends React.Component {
proxyUrl: true,
});

return fetchHar(har, `ReadMe API Explorer/${pkg.version}`).then(async res => {
const request = constructRequest(har);

// There's a bug in Firefox and Chrome where they don't respect setting a custom User-Agent on fetch() requests,
// so instead to let API metrics know that this request came from the Explorer, we're setting a vendor header
// instead.
//
// https://stackoverflow.com/questions/42815087/sending-a-custom-user-agent-string-along-with-my-headers-fetch
request.headers.append('x-readme-api-explorer', pkg.version);

return fetch(request).then(async res => {
this.props.tryItMetrics(har, res);

this.setState({
Expand Down

0 comments on commit 4100911

Please sign in to comment.