diff --git a/lib/util/http/github.spec.ts b/lib/util/http/github.spec.ts index 8a56df0207a6a7b0931aaee9c3db66eed4b7dfd8..c3ef8ad22f315817fcbef084957cf6b25eeb71bc 100644 --- a/lib/util/http/github.spec.ts +++ b/lib/util/http/github.spec.ts @@ -155,7 +155,7 @@ describe('util/http/github', () => { .scope(githubApiHost, { reqheaders: { authorization: 'token abc', - accept: 'application/vnd.github.v3+json', + accept: 'application/json, application/vnd.github.v3+json', }, }) .get(url) diff --git a/lib/util/http/index.spec.ts b/lib/util/http/index.spec.ts index 00f964975f18a26dcb8c10d92907eea9bf718c08..97226e30c161fa698ebd50050c66907afe92c283 100644 --- a/lib/util/http/index.spec.ts +++ b/lib/util/http/index.spec.ts @@ -70,7 +70,14 @@ describe('util/http/index', () => { }); it('getJson', async () => { - httpMock.scope(baseUrl).get('/').reply(200, '{ "test": true }'); + httpMock + .scope(baseUrl, { + reqheaders: { + accept: 'application/json', + }, + }) + .get('/') + .reply(200, '{ "test": true }'); expect(await http.getJson('http://renovate.com')).toEqual({ authorization: false, body: { @@ -324,7 +331,11 @@ describe('util/http/index', () => { describe('getJson', () => { it('infers body type', async () => { httpMock - .scope(baseUrl) + .scope(baseUrl, { + reqheaders: { + accept: 'application/json', + }, + }) .get('/') .reply(200, JSON.stringify({ test: true })); @@ -342,7 +353,11 @@ describe('util/http/index', () => { it('reports warnings', async () => { memCache.init(); httpMock - .scope(baseUrl) + .scope(baseUrl, { + reqheaders: { + accept: 'application/json', + }, + }) .get('/') .reply(200, JSON.stringify({ test: 'foobar' })); @@ -361,7 +376,11 @@ describe('util/http/index', () => { it('throws', async () => { httpMock - .scope(baseUrl) + .scope(baseUrl, { + reqheaders: { + accept: 'application/json', + }, + }) .get('/') .reply(200, JSON.stringify({ test: 'foobar' })); diff --git a/lib/util/http/index.ts b/lib/util/http/index.ts index 3fe4f883e5326f2ea9f1e4b926dda49c88b85912..43dc5237056945c66a3ec6a83c00759d9b9d50bd 100644 --- a/lib/util/http/index.ts +++ b/lib/util/http/index.ts @@ -245,6 +245,11 @@ export class Http<Opts extends HttpOptions = HttpOptions> { method, responseType: 'json', }; + // signal that we expect a json response + opts.headers = { + accept: 'application/json', + ...opts.headers, + }; if (body) { opts.json = body; }