You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by nd...@apache.org on 2024/09/06 16:52:42 UTC

(tika) branch tika-grpc-3x-features updated: TIKA-4272: back to additional metadata the old way

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 0a588185c TIKA-4272: back to additional metadata the old way
0a588185c is described below

commit 0a588185c616b222a2d0885baebcc78698aa83e0
Author: Nicholas DiPiazza <nd...@apache.org>
AuthorDate: Fri Sep 6 11:52:36 2024 -0500

    TIKA-4272: back to additional metadata the old way
---
 .../apache/tika/pipes/fetcher/http/HttpFetcher.java   | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 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 4047e77e8..b64d6bc8a 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
@@ -71,7 +71,6 @@ import org.apache.tika.metadata.TikaCoreProperties;
 import org.apache.tika.parser.ParseContext;
 import org.apache.tika.pipes.fetcher.AbstractFetcher;
 import org.apache.tika.pipes.fetcher.RangeFetcher;
-import org.apache.tika.pipes.fetcher.http.config.AdditionalHttpHeaders;
 import org.apache.tika.pipes.fetcher.http.config.HttpFetcherConfig;
 import org.apache.tika.pipes.fetcher.http.jwt.JwtGenerator;
 import org.apache.tika.pipes.fetcher.http.jwt.JwtPrivateKeyCreds;
@@ -138,7 +137,7 @@ public class HttpFetcher extends AbstractFetcher implements Initializable, Range
                 .setRedirectsEnabled(httpFetcherConfig.getMaxRedirects() > 0)
                 .build();
         get.setConfig(requestConfig);
-        putAdditionalHeadersOnRequest(parseContext, get);
+        putAdditionalHeadersOnRequest(get, metadata);
         return execute(get, metadata, httpClient, true);
     }
 
@@ -146,21 +145,23 @@ public class HttpFetcher extends AbstractFetcher implements Initializable, Range
     public InputStream fetch(String fetchKey, long startRange, long endRange, Metadata metadata,
                              ParseContext parseContext) throws IOException, TikaException {
         HttpGet get = new HttpGet(fetchKey);
-        putAdditionalHeadersOnRequest(parseContext, get);
+        putAdditionalHeadersOnRequest(get, metadata);
 
         get.setHeader("Range", "bytes=" + startRange + "-" + endRange);
         return execute(get, metadata, httpClient, true);
     }
 
-    private void putAdditionalHeadersOnRequest(ParseContext parseContext, HttpGet httpGet) throws TikaException {
+    private void putAdditionalHeadersOnRequest(HttpGet httpGet, Metadata requestMetadata) throws TikaException {
         if (!StringUtils.isBlank(httpFetcherConfig.getUserAgent())) {
             httpGet.setHeader(USER_AGENT, httpFetcherConfig.getUserAgent());
         }
-        AdditionalHttpHeaders additionalHttpHeaders = parseContext.get(AdditionalHttpHeaders.class);
-        if (additionalHttpHeaders != null) {
-            additionalHttpHeaders
-                    .getHeaders()
-                    .forEach(httpGet::setHeader);
+        if (requestMetadata != null) {
+            String [] httpRequestHeaders = requestMetadata.getValues("httpRequestHeaders");
+            if (httpRequestHeaders != null) {
+                for (String httpRequestHeader : httpRequestHeaders) {
+                    placeHeaderOnGetRequest(httpGet, httpRequestHeader);
+                }
+            }
         }
         if (jwtGenerator != null) {
             try {