From b3c70506486182742014823a59b70e66829db64a Mon Sep 17 00:00:00 2001 From: Andrii Grynenko Date: Wed, 15 Sep 2021 02:06:15 -0700 Subject: [PATCH] Send agent name from THeaderTransport.java Summary: One downside of this implementation is that this will be sent with the first response from the Java server as well. But I don't think any clients should care. Reviewed By: mshneer Differential Revision: D30954223 fbshipit-source-id: bbdf944ca98c6a159a26ee6e3ece1bc4ec457453 --- .../facebook/thrift/transport/THeaderTransport.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/thrift/lib/java/src/main/java/com/facebook/thrift/transport/THeaderTransport.java b/thrift/lib/java/src/main/java/com/facebook/thrift/transport/THeaderTransport.java index 2b0c88e2b3f..b9b39bee5a6 100644 --- a/thrift/lib/java/src/main/java/com/facebook/thrift/transport/THeaderTransport.java +++ b/thrift/lib/java/src/main/java/com/facebook/thrift/transport/THeaderTransport.java @@ -120,9 +120,13 @@ public int getValue() { private static final String IDENTITY_HEADER = "identity"; private static final String ID_VERSION_HEADER = "id_version"; private static final String ID_VERSION = "1"; + private static final String CLIENT_METADATA_HEADER = "client_metadata"; + private static final String CLIENT_METADATA = "{\"agent\":\"THeaderTransport.java\"}"; private String identity; + private boolean firstRequest = true; + public THeaderTransport(TTransport transport) { super(transport); writeTransforms = new ArrayList(); @@ -431,6 +435,7 @@ private void readHeaderFormat(int headerSize, byte[] buff) throws TTransportExce break; } } + readHeaders.remove(CLIENT_METADATA_HEADER); readHeaders.putAll(readPersistentHeaders); // Read in the data section. @@ -614,6 +619,11 @@ public void flushImpl(boolean oneway) throws TTransportException { transformData.limit(transformData.position()); transformData.position(0); + if (firstRequest) { + firstRequest = false; + writeHeaders.put(CLIENT_METADATA_HEADER, CLIENT_METADATA); + } + if (identity != null && identity.length() > 0) { writeHeaders.put(ID_VERSION_HEADER, ID_VERSION); writeHeaders.put(IDENTITY_HEADER, identity);