Skip to content

Commit

Permalink
Add User-Agent header to HTTP requests (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanfuller authored Nov 18, 2021
1 parent 892ccbe commit 07051ed
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ai.nightfall</groupId>
<artifactId>scan-api</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>

<name>${project.groupId}:${project.artifactId}</name>
<description>The Nightfall Scanner provides Java bindings for our developer platform, which allows clients
Expand Down Expand Up @@ -93,6 +93,18 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/ai/nightfall/scan/NightfallClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class NightfallClient implements Closeable {
private static final long wakeupDurationMillis = Duration.ofSeconds(15).toMillis();
private static final int DEFAULT_RETRY_COUNT = 5;
private static final String API_HOST = "https://api.nightfall.ai";
private final String implVersion = loadImplVersion();

private final String apiHost;
private final String apiKey;
Expand All @@ -64,6 +65,14 @@ public class NightfallClient implements Closeable {
this.httpClient = httpClient;
}

private String loadImplVersion() {
Package pkg = this.getClass().getPackage();
if (pkg == null) {
return "";
}
return pkg.getImplementationVersion();
}

/**
* Closes this client and releases underlying system resources.
*/
Expand Down Expand Up @@ -357,6 +366,10 @@ private <E> E issueRequest(
if (headers != null) {
builder.headers(headers);
}
if (this.implVersion != null && !this.implVersion.equals("")) {
builder.addHeader("User-Agent", "nightfall-java-sdk/" + this.implVersion);
}

builder.addHeader("Authorization", "Bearer " + this.apiKey);

RequestBody reqBody = null;
Expand Down

0 comments on commit 07051ed

Please sign in to comment.