Mobrovac has submitted this change and it was merged.

Change subject: Fix I2756d11 to use request instead of http lib
......................................................................


Fix I2756d11 to use request instead of http lib

Change I2756d11 used the http library, which does
not respect environment proxy settings. Fixed to
use request library instead, which will respect
the proxy settings.

Change-Id: Id9925189fbe4ac9d2efeb05cfe248e477b65932b
---
M lib/CitoidService.js
M package.json
2 files changed, 19 insertions(+), 8 deletions(-)

Approvals:
  Mobrovac: Looks good to me, approved



diff --git a/lib/CitoidService.js b/lib/CitoidService.js
index 9b3d79d..c8aadcc 100644
--- a/lib/CitoidService.js
+++ b/lib/CitoidService.js
@@ -5,7 +5,7 @@
  */
 
 /* Import Modules */
-var http = require('http');
+var request = require('request');
 var urlParse = require('url');
 
 /* Import Local Modules */
@@ -122,16 +122,27 @@
 CitoidService.prototype.requestFromDOI = function (doiOpts, callback){
        var doiLink = 'http://dx.doi.org/'+ doiOpts.search;
        var citoidService = this;
-       var urlOpts =  Object.assign({}, doiOpts); // Shallow clone doiOpts
+       // Shallow clone doiOpts for requestFromURL method
+       var urlOpts =  Object.assign({}, doiOpts);
+       // Options for obtaining url the DOI resolves to
+       var resolveOpts = {
+               url : doiLink,
+               followRedirect : false,
+       };
 
-       // Follow one redirect here from the DOI to the canonical url
-       http.get(doiLink, function (res) {
-               // Detect a redirect
-               if (res && res.statusCode > 300 && res.statusCode < 400 && 
res.headers.location) {
+       // Resolve canonical URL from DOI URL
+       request.head(resolveOpts, function (err, res) {
+               if (!err && res && res.statusCode > 300 && res.statusCode < 400 
&&
+                               res.headers.location) {
                        urlOpts.search = res.headers.location;
+                       // Send canonical URL to requestFromURL
+                       citoidService.logger.log('debug/DOI', "Resolved DOI "
+                               + doiOpts.search + " to URL " + urlOpts.search +
+                               "; Sending to requestFromURL");
                        citoidService.requestFromURL(urlOpts, callback);
                } else {
-                       citoidService.logger.log('debug/DOI', "Unable to 
resolve DOI " + doiOpts.search);
+                       citoidService.logger.log('debug/DOI', "Unable to 
resolve DOI "
+                               + doiOpts.search);
                        var message = 'Unable to resolve DOI';
                        var error = new Error(message);
                        callback(error, 404, {Error: message});
diff --git a/package.json b/package.json
index 4bdfddc..1707ab2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "citoid",
-  "version": "0.2.3",
+  "version": "0.2.4",
   "description": "Converts search terms such as URL or DOI into citations.",
   "scripts": {
     "start": "service-runner",

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Id9925189fbe4ac9d2efeb05cfe248e477b65932b
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/services/citoid
Gerrit-Branch: master
Gerrit-Owner: Mvolz <mv...@wikimedia.org>
Gerrit-Reviewer: Mobrovac <mobro...@wikimedia.org>
Gerrit-Reviewer: Mvolz <mv...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to