mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
backendSrv: Only stringifies request body if payload isn't already a string (#21639)
* backendSrv: Only stringifies request body if payload isn't already a string * Add test cases to verify behaviour
This commit is contained in:
parent
3fd8505195
commit
87af7d9987
@ -474,7 +474,7 @@ export class BackendSrv implements BackendService {
|
||||
Accept: 'application/json, text/plain, */*',
|
||||
...options.headers,
|
||||
},
|
||||
body: JSON.stringify(options.data),
|
||||
body: typeof options.data === 'string' ? options.data : JSON.stringify(options.data),
|
||||
});
|
||||
|
||||
private getFromFetchStream = (options: BackendSrvRequest) => {
|
||||
|
@ -160,7 +160,8 @@ describe('backendSrv', () => {
|
||||
${'GET'} | ${undefined} | ${undefined} | ${{ method: 'GET', headers: { 'Content-Type': 'application/json', Accept: 'application/json, text/plain, */*' }, body: undefined }}
|
||||
${'GET'} | ${{ Auth: 'Some Auth' }} | ${undefined} | ${{ method: 'GET', headers: { 'Content-Type': 'application/json', Accept: 'application/json, text/plain, */*', Auth: 'Some Auth' }, body: undefined }}
|
||||
${'GET'} | ${{ Auth: 'Some Auth' }} | ${{ data: { test: 'Some data' } }} | ${{ method: 'GET', headers: { 'Content-Type': 'application/json', Accept: 'application/json, text/plain, */*', Auth: 'Some Auth' }, body: '{"data":{"test":"Some data"}}' }}
|
||||
${'GET'} | ${{ Auth: 'Some Auth' }} | ${'some data'} | ${{ method: 'GET', headers: { 'Content-Type': 'application/json', Accept: 'application/json, text/plain, */*', Auth: 'Some Auth' }, body: '"some data"' }}
|
||||
${'GET'} | ${{ Auth: 'Some Auth' }} | ${'some data'} | ${{ method: 'GET', headers: { 'Content-Type': 'application/json', Accept: 'application/json, text/plain, */*', Auth: 'Some Auth' }, body: 'some data' }}
|
||||
${'GET'} | ${{ Auth: 'Some Auth' }} | ${'{"data":{"test":"Some data"}}'} | ${{ method: 'GET', headers: { 'Content-Type': 'application/json', Accept: 'application/json, text/plain, */*', Auth: 'Some Auth' }, body: '{"data":{"test":"Some data"}}' }}
|
||||
`(
|
||||
"when called with method: '$method', headers: '$headers' and data: '$data' then result should be '$expected'",
|
||||
({ method, headers, data, expected }) => {
|
||||
|
Loading…
Reference in New Issue
Block a user