/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package com.androidzeitgeist.webcards.processing.pre;

import android.net.Uri;

import okhttp3.Request;

/**
 * Google+ uses a JavaScript based redirector. This pre processor will extract the actual URL from
 * the redirector URL and create a new request.
 */
public class GooglePlusPreProcessor implements PreProcessor {
    private static final String URL_PREFIX = "https://plus.url.google.com/url?q=";

    @Override
    public Request process(Request request) {
        final String url = request.url().toString();

        if (url.startsWith(URL_PREFIX)) {
            final String actualUrl = Uri.parse(url).getQueryParameter("q");

            return request.newBuilder()
                    .url(actualUrl)
                    .build();
        }

        return request;
    }
}

@@ -571,13 +571,8 @@
  = %22
-https
 ://p
@@ -599,16 +599,16 @@
 rl?q=%22;%0A
+
 %0A    @Ov
@@ -734,18 +734,16 @@
 url.
-startsWith
+contains
 (URL
@@ -827,24 +827,65 @@
 eter(%22q%22);%0A%0A
+            if (actualUrl != null) %7B%0A    
             
@@ -932,16 +932,20 @@
         
+    
 .url(act
@@ -972,16 +972,20 @@
         
+   
+ 
 .build()
@@ -986,16 +986,30 @@
 uild();%0A
+            %7D%0A
         

Make Google+ pre processor less strict.