-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Accept context via header X-Parse-Cloud-Context #7437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
6e75987
0c23bfd
9e24f48
119aee4
a1be895
3158916
0fa1d3a
bb972b8
a551957
8503ce6
3d4a4dd
33087a0
9aedefb
6808c05
8da1e4c
a3e6e66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,14 @@ const getMountForRequest = function (req) { | |
// req.auth - the Auth for this request | ||
export function handleParseHeaders(req, res, next) { | ||
var mount = getMountForRequest(req); | ||
|
||
let context = {}; | ||
if (req.get('X-Parse-Cloud-Context') != null) { | ||
try { | ||
context = JSON.parse(req.get('X-Parse-Cloud-Context')); | ||
} catch (e) { | ||
return malformedContext(req, res); | ||
} | ||
} | ||
var info = { | ||
appId: req.get('X-Parse-Application-Id'), | ||
sessionToken: req.get('X-Parse-Session-Token'), | ||
|
@@ -35,7 +42,7 @@ export function handleParseHeaders(req, res, next) { | |
dotNetKey: req.get('X-Parse-Windows-Key'), | ||
restAPIKey: req.get('X-Parse-REST-API-Key'), | ||
clientVersion: req.get('X-Parse-Client-Version'), | ||
context: {}, | ||
context: context, | ||
}; | ||
|
||
var basicAuth = httpAuth(req); | ||
|
@@ -105,8 +112,16 @@ export function handleParseHeaders(req, res, next) { | |
info.masterKey = req.body._MasterKey; | ||
delete req.body._MasterKey; | ||
} | ||
if (req.body._context && req.body._context instanceof Object) { | ||
info.context = req.body._context; | ||
if (req.body._context) { | ||
if (req.body._context instanceof Object) { | ||
info.context = req.body._context; | ||
} else { | ||
try { | ||
info.context = JSON.parse(req.body._context); | ||
mtrezza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} catch (e) { | ||
return malformedContext(req, res); | ||
} | ||
} | ||
delete req.body._context; | ||
} | ||
if (req.body._ContentType) { | ||
|
@@ -454,3 +469,8 @@ function invalidRequest(req, res) { | |
res.status(403); | ||
res.end('{"error":"unauthorized"}'); | ||
} | ||
|
||
function malformedContext(req, res) { | ||
res.status(500); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error is caused by a developer mistake, so it should be a 4xx response code. I suggest
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switched to |
||
res.json({ code: Parse.Error.INVALID_JSON, error: 'Invalid object for context.' }); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.