Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have a deployed website behind a reverse proxy that is not configured correctly to send the x-forward-proto header. As a result, the back-end sends some json values as http when they should instead be https ( ref: https://spring.io/guides/gs/rest-hateoas/ ) .

As a temporary testing solution I have made the following firefox greesemonkey userscript.

// ==UserScript==
// @name        ATPatchJsonProtocol_01
// @namespace   https://WEBSITEURL
// @description Replaces http with https in json responses
// @include     https://WEBSITEURL/*
// @version     1
// @grant       none
// ==/UserScript==

var vctApp = angular.module('app');

vctApp.factory('myInterceptor', ['$q', function($q) {  

    var responseInterceptor = {
         response: function (response) {
            if(response.data != undefined) //or response.data
              var asString = JSON.stringify(response.data);
              asString = asString.replace(/http/g, 'https');
              response.data = JSON.parse(asString);
            return response;
        }
    };

    return responseInterceptor;

}])
.config(function ($httpProvider) {

    //alert(JSON.stringify($httpProvider.interceptors);

    $httpProvider.interceptors.push('myInterceptor');
});

alert('You are currently running a greesemonkey user script that adds delays for AT site.\nThe script modifies server responses to allow the app to function with a incomplete reverse proxy configuration.');

Comments/corrections/suggestions?

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.