Skip to content

Commit

Permalink
chore: include client details in header (#109)
Browse files Browse the repository at this point in the history
* Include version in User-Agent header

* Use fallback value for version in header

* Whoops
  • Loading branch information
dmbrooke authored Oct 24, 2023
1 parent af59ac7 commit af659b6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@
<version>1.7.0</version>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>3.9.5</version>
</dependency>


</dependencies>
<repositories>
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/com/coveo/pushapiclient/PlatformClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.io.FileReader;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
Expand All @@ -11,6 +12,8 @@
import java.util.HashMap;
import java.util.stream.Stream;
import org.apache.logging.log4j.LogManager;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;

/** PlatformClient handles network requests to the Coveo platform */
public class PlatformClient {
Expand Down Expand Up @@ -567,7 +570,23 @@ private String[] getAuthorizationHeader() {
}

private String[] getContentTypeApplicationJSONHeader() {
return new String[] {"Content-Type", "application/json", "Accept", "application/json"};
MavenXpp3Reader reader = new MavenXpp3Reader();
String version = "";
try {
Model model = reader.read(new FileReader("pom.xml"));
version = model.getVersion();
} catch (Exception e) {
version = "Not-Available";
}

return new String[] {
"Content-Type",
"application/json",
"Accept",
"application/json",
"User-Agent",
String.format("CoveoSDKJava/%s", version)
};
}

private String[] getAes256Header() {
Expand Down

0 comments on commit af659b6

Please sign in to comment.