Skip to content

Commit d5f86be

Browse files
committed
handle 308 redirect
1 parent eaddb1b commit d5f86be

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

integration/test/ParseServerTest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ describe('ParseServer', () => {
3939
});
4040

4141
it('can forward redirect', async () => {
42+
const serverURL = Parse.serverURL;
4243
http.createServer(function(_, res) {
43-
res.writeHead(301, { Location: 'http://localhost:1337/parse' });
44+
res.writeHead(301, { Location: serverURL });
4445
res.end();
4546
}).listen(8080);
46-
const serverURL = Parse.serverURL;
4747
Parse.CoreManager.set('SERVER_URL', 'http://localhost:8080/api');
4848
const object = new TestObject({ foo: 'bar' });
4949
await object.save();

src/RESTController.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,14 @@ const RESTController = {
197197
} else if (status >= 400 && status < 500) {
198198
const error = await response.json();
199199
promise.reject(error);
200-
} else if (status === 301 || status === 302 || status === 303 || status === 307) {
200+
} else if ([301, 302, 303, 307, 308].includes(status)) {
201201
const location = response.headers.get('location');
202-
promise.resolve({ status, location, method: status === 303 ? 'GET' : method });
202+
promise.resolve({
203+
status,
204+
location,
205+
method: status === 303 ? 'GET' : method,
206+
body: status === 303 ? null : data,
207+
});
203208
} else if (status >= 500 || status === 0) {
204209
// retry on 5XX or library error
205210
if (++attempts < CoreManager.get('REQUEST_ATTEMPT_LIMIT')) {
@@ -311,7 +316,7 @@ const RESTController = {
311316
return RESTController.ajax(method, url, payloadString, {}, options).then(async (result) => {
312317
if (result.location) {
313318
const newURL = getPath(result.location, path);
314-
result = await RESTController.ajax(result.method, newURL, payloadString, {}, options);
319+
result = await RESTController.ajax(result.method, newURL, result.body, {}, options);
315320
}
316321
const { response, status, headers } = result;
317322
if (options.returnStatus) {

0 commit comments

Comments
 (0)