Skip to content

Commit 8cfead2

Browse files
author
Marko Obrovac
committed
Parsoid: Stash: Honour our own ETag when retrieving the stash
If a client is switching between wikitext and HTML and in one of the two transforms they fail to provide the revision in the URI, trust that the ETag is correct and try to retrieve the stashed content using the information in the ETag. As a fall-back, though, try with the client-supplied revision as well. This is a port of #1208 to the proxy branch. Bug: T235465
1 parent a5d5f5d commit 8cfead2

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lib/parsoid.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,24 @@ class ParsoidService {
590590
contentPromise = P.resolve(undefined);
591591
} else {
592592
if (etag && etag.suffix === 'stash' && from === 'html' && to === 'wikitext') {
593+
// T235465: RB should trust its own ETag over the client-supplied revision, but
594+
// allow for the client to be right, so provide their revision as a fall-back
595+
const revMismatch = etag.rev !== rp.revision;
596+
if (revMismatch) {
597+
// the ETag and URI parameter do not agree, log this (for now?)
598+
hyper.logger.log('warn/parsoid/etag_rev', {
599+
msg: 'The revisions in If-Match and URI differ'
600+
});
601+
}
593602
contentPromise = this._getStashedContent(hyper, rp.domain,
594-
rp.title, rp.revision, tid);
603+
rp.title, etag.rev, etag.tid)
604+
.catch({ status: 404 }, (e) => {
605+
if (!revMismatch) {
606+
// the revisions match, so this is a genuine 404
607+
throw e;
608+
}
609+
return this._getStashedContent(hyper, rp.domain, rp.title, rp.revision, tid);
610+
});
595611
} else {
596612
contentPromise = this._getOriginalContent(hyper, req, rp.revision, tid);
597613
}

0 commit comments

Comments
 (0)