[maven-javadoc-plugin] branch MJAVADOC-533 created (now 407343b)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[maven-javadoc-plugin] branch MJAVADOC-533 created (now 407343b)

gboue
This is an automated email from the ASF dual-hosted git repository.

gboue pushed a change to branch MJAVADOC-533
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git.


      at 407343b  [MJAVADOC-533] <link> entries that point to a resource that requires an Accept header may be ignored

This branch includes the following new commits:

     new 407343b  [MJAVADOC-533] <link> entries that point to a resource that requires an Accept header may be ignored

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Reply | Threaded
Open this post in threaded view
|

[maven-javadoc-plugin] 01/01: [MJAVADOC-533] <link> entries that point to a resource that requires an Accept header may be ignored

gboue
This is an automated email from the ASF dual-hosted git repository.

gboue pushed a commit to branch MJAVADOC-533
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git

commit 407343bad4cba9431cb490746ca9257c7a6f7594
Author: Guillaume Boué <[hidden email]>
AuthorDate: Thu Aug 9 21:29:13 2018 +0200

    [MJAVADOC-533] <link> entries that point to a resource that requires an
    Accept header may be ignored
   
    Add a */* Accept header, that is required by some servers
---
 .../apache/maven/plugins/javadoc/JavadocUtil.java  |  6 ++++
 .../maven/plugins/javadoc/JavadocUtilTest.java     | 40 ++++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
index 5881549..c7467ae 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
@@ -19,6 +19,7 @@ package org.apache.maven.plugins.javadoc;
  * under the License.
  */
 
+import org.apache.http.HttpHeaders;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
@@ -32,6 +33,7 @@ import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.conn.params.ConnRoutePNames;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.impl.conn.PoolingClientConnectionManager;
+import org.apache.http.message.BasicHeader;
 import org.apache.http.params.CoreConnectionPNames;
 import org.apache.http.params.CoreProtocolPNames;
 import org.apache.maven.plugin.logging.Log;
@@ -1816,6 +1818,10 @@ public class JavadocUtil
         httpClient.getParams().setParameter( CoreProtocolPNames.USER_AGENT,
                                              "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" );
 
+        // Some server reject requests that do not have an Accept header
+        httpClient.getParams().setParameter( ClientPNames.DEFAULT_HEADERS,
+                                             Arrays.asList( new BasicHeader( HttpHeaders.ACCEPT, "*/*" ) ) );
+
         if ( settings != null && settings.getActiveProxy() != null )
         {
             Proxy activeProxy = settings.getActiveProxy();
diff --git a/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java b/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java
index 8e9b33f..fa5bfaa 100644
--- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java
+++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java
@@ -618,6 +618,46 @@ public class JavadocUtilTest
     }
 
     /**
+     * Tests that getRedirectUrl adds an Accept header in HTTP requests. Necessary because some sites like Cloudflare
+     * reject requests without an Accept header.
+     */
+    public void testGetRedirectUrlVerifyHeaders()
+        throws Exception
+    {
+        Server server = null;
+        try
+        {
+            server = new Server( 0 );
+            server.addHandler( new AbstractHandler()
+            {
+                @Override
+                public void handle( String target, HttpServletRequest request, HttpServletResponse response,
+                                    int dispatch )
+                    throws IOException, ServletException
+                {
+                    if ( request.getHeader( "Accept" ) == null )
+                    {
+                        response.setStatus( HttpServletResponse.SC_FORBIDDEN );
+                    }
+                    else
+                    {
+                        response.setStatus( HttpServletResponse.SC_OK );
+                    }
+                    response.getOutputStream().close();
+                }
+            } );
+            server.start();
+
+            URL url = new URI( "http://localhost:" + server.getConnectors()[0].getLocalPort() ).toURL();
+            JavadocUtil.getRedirectUrl( url, new Settings() );
+        }
+        finally
+        {
+            stopSilently( server );
+        }
+    }
+
+    /**
      * Method to test copyJavadocResources()
      *
      * @throws Exception if any