Skip to content

Commit 07051ed

Browse files
authored
Add User-Agent header to HTTP requests (#24)
1 parent 892ccbe commit 07051ed

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

pom.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>ai.nightfall</groupId>
88
<artifactId>scan-api</artifactId>
9-
<version>1.0.1</version>
9+
<version>1.0.2</version>
1010

1111
<name>${project.groupId}:${project.artifactId}</name>
1212
<description>The Nightfall Scanner provides Java bindings for our developer platform, which allows clients
@@ -93,6 +93,18 @@
9393
</execution>
9494
</executions>
9595
</plugin>
96+
<plugin>
97+
<groupId>org.apache.maven.plugins</groupId>
98+
<artifactId>maven-jar-plugin</artifactId>
99+
<version>3.2.0</version>
100+
<configuration>
101+
<archive>
102+
<manifest>
103+
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
104+
</manifest>
105+
</archive>
106+
</configuration>
107+
</plugin>
96108
<plugin>
97109
<groupId>org.apache.maven.plugins</groupId>
98110
<artifactId>maven-javadoc-plugin</artifactId>

src/main/java/ai/nightfall/scan/NightfallClient.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class NightfallClient implements Closeable {
4646
private static final long wakeupDurationMillis = Duration.ofSeconds(15).toMillis();
4747
private static final int DEFAULT_RETRY_COUNT = 5;
4848
private static final String API_HOST = "https://api.nightfall.ai";
49+
private final String implVersion = loadImplVersion();
4950

5051
private final String apiHost;
5152
private final String apiKey;
@@ -64,6 +65,14 @@ public class NightfallClient implements Closeable {
6465
this.httpClient = httpClient;
6566
}
6667

68+
private String loadImplVersion() {
69+
Package pkg = this.getClass().getPackage();
70+
if (pkg == null) {
71+
return "";
72+
}
73+
return pkg.getImplementationVersion();
74+
}
75+
6776
/**
6877
* Closes this client and releases underlying system resources.
6978
*/
@@ -357,6 +366,10 @@ private <E> E issueRequest(
357366
if (headers != null) {
358367
builder.headers(headers);
359368
}
369+
if (this.implVersion != null && !this.implVersion.equals("")) {
370+
builder.addHeader("User-Agent", "nightfall-java-sdk/" + this.implVersion);
371+
}
372+
360373
builder.addHeader("Authorization", "Bearer " + this.apiKey);
361374

362375
RequestBody reqBody = null;

0 commit comments

Comments
 (0)