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

ndipiazza pushed a commit to branch tika-grpc-3x-features
in repository https://gitbox.apache.org/repos/asf/tika.git


The following commit(s) were added to refs/heads/tika-grpc-3x-features by this 
push:
     new 15d57f1ad TIKA-4272: fix issue with headers for all requests
15d57f1ad is described below

commit 15d57f1add8398fb9e63db25dbcb848dd7313b4c
Author: Nicholas DiPiazza <[email protected]>
AuthorDate: Fri Sep 6 11:24:58 2024 -0500

    TIKA-4272: fix issue with headers for all requests
---
 .../org/apache/tika/pipes/fetcher/http/HttpFetcher.java  | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git 
a/tika-pipes/tika-fetchers/tika-fetcher-http/src/main/java/org/apache/tika/pipes/fetcher/http/HttpFetcher.java
 
b/tika-pipes/tika-fetchers/tika-fetcher-http/src/main/java/org/apache/tika/pipes/fetcher/http/HttpFetcher.java
index 649a2b0ea..4047e77e8 100644
--- 
a/tika-pipes/tika-fetchers/tika-fetcher-http/src/main/java/org/apache/tika/pipes/fetcher/http/HttpFetcher.java
+++ 
b/tika-pipes/tika-fetchers/tika-fetcher-http/src/main/java/org/apache/tika/pipes/fetcher/http/HttpFetcher.java
@@ -169,9 +169,18 @@ public class HttpFetcher extends AbstractFetcher 
implements Initializable, Range
                 throw new TikaException("Could not generate JWT", e);
             }
         }
+        placeHeadersOnGetRequest(httpGet);
     }
 
-    private static void placeHeaderOnGetRequest(HttpGet get, String 
httpRequestHeader) {
+    private void placeHeadersOnGetRequest(HttpGet httpGet) {
+        if (httpFetcherConfig.getHttpRequestHeaders() != null) {
+            for (String httpRequestHeader : 
httpFetcherConfig.getHttpRequestHeaders()) {
+                placeHeaderOnGetRequest(httpGet, httpRequestHeader);
+            }
+        }
+    }
+
+    private void placeHeaderOnGetRequest(HttpGet httpGet, String 
httpRequestHeader) {
         int idxOfEquals = httpRequestHeader.indexOf(':');
         if (idxOfEquals == -1) {
             return;
@@ -182,9 +191,10 @@ public class HttpFetcher extends AbstractFetcher 
implements Initializable, Range
         String headerValue = httpRequestHeader
                 .substring(idxOfEquals + 1)
                 .trim();
-        get.setHeader(headerKey, headerValue);
+        httpGet.setHeader(headerKey, headerValue);
     }
 
+
     private InputStream execute(HttpGet get, Metadata metadata, HttpClient 
client, boolean retryOnBadLength) throws IOException {
         HttpClientContext context = HttpClientContext.create();
         HttpResponse response = null;
@@ -299,7 +309,7 @@ public class HttpFetcher extends AbstractFetcher implements 
Initializable, Range
                     .getValue());
         }
 
-        //load headers
+        //load response headers
         if (httpFetcherConfig.getHttpHeaders() != null) {
             for (String h : httpFetcherConfig.getHttpHeaders()) {
                 Header[] headers = response.getHeaders(h);

Reply via email to