Slingql call should use application/json as the Content Type
The Slingql call is currently sending the data as form-data, which doesn't play well with the new caching structure we're setting up. Instead this should be changed to use application/json as the content type and send the data as the body.
Example:
This is what's currently being sent over:
Posting Axios Settings {
method: 'post',
url: '/bin/slingql',
headers: {
'content-type': 'multipart/form-data; boundary=--------------------------791708339597243672587101'
},
data: FormData {
_overheadLength: 212,
_valueLength: 140,
_valuesToMeasure: [],
writable: false,
readable: true,
dataSize: 0,
maxDataSize: 2097152,
pauseStreams: true,
_released: false,
_streams: [
'----------------------------791708339597243672587101\r\n' +
'Content-Disposition: form-data; name="query"\r\n' +
'\r\n',
'{af40850f79629894da5b086405df59434a50c89d7ce5ad525a0b3feddba72cc5b:resource(path:"/content/fshr/collections"){children{name,path}path}}',
[Function: bound ],
'----------------------------791708339597243672587101\r\n' +
'Content-Disposition: form-data; name="_charset_"\r\n' +
'\r\n',
'utf-8',
[Function: bound ]
],
_currentStream: null,
_insideLoop: false,
_pendingNext: false,
_boundary: '--------------------------791708339597243672587101'
}
}
This is what we want
Posting Axios Settings {
method: 'post',
url: '/bin/slingql',
data: {
query: '{af40850f79629894da5b086405df59434a50c89d7ce5ad525a0b3feddba72cc5b:resource(path:"/content/fshr/collections"){children{name,path}path}}',
_charset_: 'utf-8'
},
headers: { 'Content-Type': 'application/json' }
}
I verified that using this approach should work just find with how things are running on AEM. The difficulty is going to be how to structure the call within the sling-connector. We basically want to just use Axios's default handling for setting the content type. It'll automatically set it to 'application/json' if an object is passed as the data (vs the FormData object we're currently using).
ex:
const axiosSettings={
method: 'post',
url: path,
auth:sc_self.makeAuth(),
data: params,
headers: {"Content-Type":"application/json"},
}
I still think it'd be best to keep doing this via the SC.post function (so we don't have to repeat any error handling, etc. Plus I think it'd just be a good option to support), but that might not be easily doable without adding an optional options
param to the function. And that might not be easily doable because of the backwards support for both Callbacks and Promises. Looking through I think it could be done though using type checking and some hierarchy of checks (see SC.get for a good example of that).