BearND has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/372202 )

Change subject: Allow custom content types
......................................................................

Allow custom content types

Previously we only had application/json content types.
Now we also allow other types.
To keep the changes small application/json is the default.

Change-Id: I12b48900c02eb8c8695cac591814fe8ccb047b18
---
M lib/mobile-util.js
M test/utils/headers.js
2 files changed, 7 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps 
refs/changes/02/372202/1

diff --git a/lib/mobile-util.js b/lib/mobile-util.js
index d6c26b0..7f47f13 100644
--- a/lib/mobile-util.js
+++ b/lib/mobile-util.js
@@ -16,7 +16,7 @@
     unpublished: { name: 'unpublished', version: '0.0.0' }
 };
 
-mUtil.setContentType = function(res, spec) {
+mUtil.setContentType = function(res, spec, mainType = 'application/json') {
     if (!spec.name || !spec.version) {
         throw new HTTPError({
             status: 500,
@@ -26,7 +26,7 @@
         });
     }
 
-    res.type(`application/json; charset=utf-8; 
profile="https://www.mediawiki.org/wiki/Specs/${spec.name}/${spec.version}"`);
+    res.type(`${mainType}; charset=utf-8; 
profile="https://www.mediawiki.org/wiki/Specs/${spec.name}/${spec.version}"`);
 };
 
 /**
diff --git a/test/utils/headers.js b/test/utils/headers.js
index c42b4a9..0447ba3 100644
--- a/test/utils/headers.js
+++ b/test/utils/headers.js
@@ -4,13 +4,15 @@
 const assert = require('./assert.js');
 const preq   = require('preq');
 
+const PROFILE_REGEX = 
'profile="https://www.mediawiki.org/wiki/Specs/[A-Za-z-]+/\\d+\\.\\d+\\.\\d+"$';
+const JSON_CONTENT_TYPE_REGEX = `^application/json; charset=utf-8; 
${PROFILE_REGEX}`;
+const HTML_CONTENT_TYPE_REGEX = `^text/html; charset=utf-8; ${PROFILE_REGEX}`;
 
 function checkHeaders(uri, expContentType) {
     return preq.get({ uri })
         .then((res) => {
             assert.deepEqual(res.status, 200);
-            expContentType = expContentType || '^application/json; 
charset=utf-8; '
-                + 
'profile="https://www.mediawiki.org/wiki/Specs/[a-z-]+/\\d+\\.\\d+\\.\\d+"$';
+            expContentType = expContentType || JSON_CONTENT_TYPE_REGEX;
             assert.contentType(res, expContentType);
             assert.deepEqual(res.headers.etag, '^"[^/"]+/[^/"]+"$',
                 'The ETag header is not present or invalid');
@@ -31,5 +33,6 @@
 
 
 module.exports = {
+    HTML_CONTENT_TYPE_REGEX,
     checkHeaders
 };

-- 
To view, visit https://gerrit.wikimedia.org/r/372202
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I12b48900c02eb8c8695cac591814fe8ccb047b18
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: BearND <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to