]> source.dussan.org Git - jgit.git/commitdiff
Add TransportHttp#getAdditionalHeaders 56/201656/2
authorMatthias Sohn <matthias.sohn@sap.com>
Tue, 2 May 2023 11:31:30 +0000 (13:31 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Wed, 3 May 2023 00:40:41 +0000 (02:40 +0200)
to enable inspecting which additional HTTP headers have been set on the
transport.

Change-Id: I0771be9cb7c837de7c203b7f044109b9b2a7d7ad

org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SetAdditionalHeadersTest.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java

index 0ea15d39e58404dc94831f7174aca3b8184d36a6..cda2b325296b1ce99363ee51519ec9fc3dd03067 100644 (file)
@@ -18,6 +18,7 @@ import java.io.IOException;
 import java.net.URI;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.eclipse.jetty.servlet.DefaultServlet;
 import org.eclipse.jetty.servlet.ServletContextHandler;
@@ -84,8 +85,15 @@ public class SetAdditionalHeadersTest extends AllFactoriesHttpTestCase {
                        HashMap<String, String> headers = new HashMap<>();
                        headers.put("Cookie", "someTokenValue=23gBog34");
                        headers.put("AnotherKey", "someValue");
-                       ((TransportHttp) t).setAdditionalHeaders(headers);
+
+                       @SuppressWarnings("resource")
+                       TransportHttp th = (TransportHttp) t;
+                       th.setAdditionalHeaders(headers);
                        t.openFetch();
+
+                       Map<String, String> h = th.getAdditionalHeaders();
+                       assertEquals("someTokenValue=23gBog34", h.get("Cookie"));
+                       assertEquals("someValue", h.get("AnotherKey"));
                }
 
                List<AccessEvent> requests = getRequests();
index 405373a0f9a87da9009eee5bd086307904a37b57..df034bdc8bb353a3b019c709cd48a1999fbc355a 100644 (file)
@@ -588,6 +588,17 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
                this.headers = headers;
        }
 
+       /**
+        * Get additional headers on the HTTP connection
+        *
+        * @return unmodifiable map of additional name:values that are set as
+        *         headers on the HTTP connection
+        * @since 6.6
+        */
+       public Map<String, String> getAdditionalHeaders() {
+               return Collections.unmodifiableMap(headers);
+       }
+
        private NoRemoteRepositoryException createNotFoundException(URIish u,
                        URL url, String msg) {
                String text;