Skip to content

Commit 3944b0e

Browse files
committed
[DE-427] user agent
1 parent e8218e4 commit 3944b0e

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

driver/src/main/java/com/arangodb/internal/http/HttpConnection.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020

2121
package com.arangodb.internal.http;
2222

23-
import com.arangodb.ArangoDBException;
24-
import com.arangodb.ContentType;
25-
import com.arangodb.DbName;
26-
import com.arangodb.Protocol;
23+
import com.arangodb.*;
2724
import com.arangodb.internal.net.Connection;
2825
import com.arangodb.internal.net.HostDescription;
2926
import com.arangodb.internal.serde.InternalSerde;
@@ -73,6 +70,7 @@ public class HttpConnection implements Connection {
7370
private static final Logger LOGGER = LoggerFactory.getLogger(HttpConnection.class);
7471
private static final String CONTENT_TYPE_APPLICATION_JSON_UTF8 = "application/json; charset=utf-8";
7572
private static final String CONTENT_TYPE_VPACK = "application/x-velocypack";
73+
private static final String USER_AGENT = "ArangoDB-JavaDriver/" + PackageVersion.VERSION;
7674
private static final AtomicInteger THREAD_COUNT = new AtomicInteger();
7775
private final InternalSerde util;
7876
private final ContentType contentType;
@@ -250,6 +248,7 @@ public void doExecute(final InternalRequest request, final CompletableFuture<Int
250248
}
251249
addHeader(request, httpRequest);
252250
httpRequest.putHeader(HttpHeaders.AUTHORIZATION.toString(), auth);
251+
httpRequest.putHeader(HttpHeaders.USER_AGENT.toString(), USER_AGENT);
253252

254253
byte[] reqBody = request.getBody();
255254
Buffer buffer;

driver/src/test/java/com/arangodb/PackageVersionTest.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package com.arangodb;
22

3+
import com.arangodb.internal.config.FileConfigPropertiesProvider;
4+
import com.fasterxml.jackson.databind.JsonNode;
35
import org.junit.jupiter.api.Test;
6+
import org.junit.jupiter.params.ParameterizedTest;
7+
import org.junit.jupiter.params.provider.EnumSource;
48
import ru.lanwen.verbalregex.VerbalExpression;
59

610
import static org.assertj.core.api.Assertions.assertThat;
11+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
712

8-
class PackageVersionTest {
13+
class PackageVersionTest extends BaseJunit5 {
914

1015
@Test
1116
void packageVersion() {
@@ -24,4 +29,21 @@ void packageVersion() {
2429
.build();
2530
assertThat(PackageVersion.VERSION).matches(testRegex.toString());
2631
}
32+
33+
@ParameterizedTest
34+
@EnumSource(Protocol.class)
35+
void userAgentHeader(Protocol protocol) {
36+
assumeTrue(protocol != Protocol.VST);
37+
ArangoDB adb = new ArangoDB.Builder()
38+
.loadProperties(new FileConfigPropertiesProvider())
39+
.useProtocol(protocol)
40+
.build();
41+
42+
Response<JsonNode> resp = adb.execute(Request.builder()
43+
.method(Request.Method.GET)
44+
.path("/_admin/echo")
45+
.build(), JsonNode.class);
46+
assertThat(resp.getBody().get("headers").get("user-agent").textValue()).endsWith(PackageVersion.VERSION);
47+
adb.shutdown();
48+
}
2749
}

0 commit comments

Comments
 (0)