[proxy] Fix proxy to be able to re-send request body (#5361)

Fixes #5360

This adds a small cache of the request body to ensure that it can be
re-sent.

TODO: still needs tested
diff --git a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/proxy/TestProxy.java b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/proxy/TestProxy.java
index bb181cc..10af298 100644
--- a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/proxy/TestProxy.java
+++ b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/proxy/TestProxy.java
@@ -25,6 +25,7 @@
 import lombok.Cleanup;
 
 import org.apache.pulsar.client.admin.PulsarAdmin;
+import org.apache.pulsar.client.api.MessageId;
 import org.apache.pulsar.client.api.Producer;
 import org.apache.pulsar.client.api.PulsarClient;
 import org.apache.pulsar.client.api.Schema;
@@ -55,6 +56,7 @@
             .withEnv("clusterName", clusterName);
 
         specBuilder.externalService("proxy-via-url", proxyViaURL);
+
         return super.beforeSetupCluster(clusterName, specBuilder);
     }
 
@@ -108,4 +110,26 @@
         testProxy(proxyViaURL.getPlainTextServiceUrl(), proxyViaURL.getHttpServiceUrl());
     }
 
+    @Test
+    public void testProxyRequestBodyRedirect() throws Exception {
+        // See GH issue #5360, this ensures that we properly get a request with a body to be processed
+        final String tenant = "proxy-test-" + randomName(10);
+        final String namespace = tenant + "/ns1";
+        final String topic = "persistent://" + namespace + "/topic1";
+
+        @Cleanup
+        PulsarAdmin admin = PulsarAdmin.builder()
+                .serviceHttpUrl(pulsarCluster.getPlainTextServiceUrl())
+                .build();
+
+        admin.tenants().createTenant(tenant,
+                new TenantInfo(Collections.emptySet(), Collections.singleton(pulsarCluster.getClusterName())));
+
+        admin.namespaces().createNamespace(namespace, Collections.singleton(pulsarCluster.getClusterName()));
+
+        for (int i = 0; i < 10; i++) {
+            // Ensure we the command works even if re-directs happen with a request body
+            admin.topics().createSubscription(topic, "test-" + i, MessageId.earliest);
+        }
+    }
 }