Skip to content

Commit d06f4a4

Browse files
committed
mm-apmspii-526: add in test for no content location
1 parent 282c0e1 commit d06f4a4

3 files changed

Lines changed: 42 additions & 9 deletions

File tree

docker/async-slowapp/src/handlers.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ async function slow(req, res, next) {
221221

222222
let delay = req.query.delay;
223223

224+
let nocl = req.query.nocl;
225+
224226
if (delay !== undefined) {
225227
delay = parseFloat(delay);
226228
await sleep(delay*1000);
@@ -237,6 +239,10 @@ async function slow(req, res, next) {
237239

238240
let location = `${locals.base_uri}/poll?id=${poll_id}`;
239241

242+
if (nocl === '1') {
243+
location = `${location}&nocl=1`;
244+
}
245+
240246
let headers = new MultiValueHeaders([
241247
"Content-Type", "application/json",
242248
"Content-Location", location
@@ -262,18 +268,19 @@ async function delete_poll(req, res, next) {
262268
respond(req, res, next, 200);
263269
}
264270

265-
let poll_counter = 0;
271+
266272
async function poll(req, res, next) {
267273

268274
let poll_id = req.query.id;
275+
let nocl = req.query.nocl;
269276
let headers = req.rawHeaders.asMultiValue();
270277
let cookies = headers.cookies('cookie');
271278
let locals = req.app.locals;
272279

273280
let poll_count = cookies['poll-count'];
274281

275282
if (poll_count !== undefined) {
276-
poll_counter++
283+
poll_count = (parseInt(poll_count.split('=')[1]) + 1).toString();
277284
}
278285

279286
if (!(poll_id in locals.tracked)) {
@@ -283,17 +290,25 @@ async function poll(req, res, next) {
283290

284291
let tracking = locals.tracked[poll_id];
285292

286-
if (new Date() < tracking.finish_at) {
287-
respond(req, res, next, 202, new MultiValueHeaders(['Content-Location', `${locals.base_uri}/poll?id=${poll_id}`]));
288-
return;
289-
}
290293

291294
let resp_headers = new MultiValueHeaders();
292295

293296
if (poll_count !== undefined) {
294-
resp_headers.withNewCookies({"poll-count": `poll-count=${poll_counter}`}, 'set-cookie');
297+
resp_headers.withNewCookies({"poll-count": `poll-count=${poll_count}`}, 'set-cookie');
298+
}
299+
300+
301+
if (new Date() < tracking.finish_at) {
302+
303+
if (nocl !== '1') {
304+
resp_headers.set('Content-Location', `${locals.base_uri}/poll?id=${poll_id}`)
305+
}
306+
respond(req, res, next, 202, resp_headers);
307+
return;
295308
}
296309

310+
311+
297312
delete locals.tracked[poll_id];
298313

299314
respond(req, res, next, tracking.final_status, resp_headers);

docker/sync-wrap/src/app.slowapp.spec.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,21 @@ describe("express with slowap", function () {
144144
assert.isAbove(pollCount, 1);
145145
done();
146146
})
147-
}).timeout(10000)
147+
}).timeout(10000);
148+
149+
150+
it("GET /slow?nocl=1, don't set content location on poll", (done) => {
151+
request(server)
152+
.get(`/slow?final_status=200&complete_in=3&nocl=1`)
153+
.set("x-sync-wait", "5")
154+
.expect(200)
155+
.then(({ headers }) => {
156+
const pollCount = parseInt(headers["set-cookie"][0].split("=")[1]);
157+
assert.isAbove(pollCount, 1);
158+
done();
159+
})
160+
}).timeout(10000);
161+
148162
});
149163

150164

docker/sync-wrap/src/handlers.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,10 @@ async function proxy(req, res, next) {
472472
let response = outcome.response;
473473
let headers = outcome.headers.withPreviousCookies(outcome.options.received_cookies);
474474
if (outcome.response.statusCode === 202) {
475+
if (headers.has('content-location')) {
476+
let poll_location = new URL(headers.get("content-location"));
477+
outcome.options.path = poll_location.pathname + poll_location.search;
478+
}
475479
outcome.options.last_response = response;
476480
outcome.options.last_headers = headers;
477481
outcome.options.received_cookies = headers.cookies("set-cookie");
@@ -514,7 +518,7 @@ async function proxy(req, res, next) {
514518
await send_response(response.statusCode, {headers: headers, response: response});
515519
})
516520
.catch(async (fin) => {
517-
await send_response(fin.error === "timeout" ? 504 : 502, {headers: headers, error: fin.error || error});
521+
await send_response(fin.error === "timeout" ? 504 : 502, {headers: headers, error: fin.error || fin});
518522
});
519523

520524
}

0 commit comments

Comments
 (0)