Skip to content

Commit

Permalink
custom product and version for HttpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
BuddahLD committed Feb 27, 2019
1 parent df6f526 commit b0abc51
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/kotlin/com/virgilsecurity/keyknox/client/HttpClient.kt
Expand Up @@ -49,6 +49,18 @@ import java.net.URL
import java.util.logging.Level

class HttpClient : HttpClientProtocol, Loggable {

private val virgilAgentHeader: String

constructor() {
virgilAgentHeader =
"$VIRGIL_AGENT_PRODUCT;$VIRGIL_AGENT_FAMILY;${OsUtils.getOsAgentName()};${VersionVirgilAgent.VERSION}"
}

constructor(product: String, version: String) {
virgilAgentHeader = "$product;$VIRGIL_AGENT_FAMILY;${OsUtils.getOsAgentName()};$version"
}

override fun send(url: URL, method: Method, accessToken: String, body: Any?, headers: Map<String, String>?): Response {
try {
logger().fine("${method.name} to $url")
Expand Down Expand Up @@ -119,7 +131,7 @@ class HttpClient : HttpClientProtocol, Loggable {
urlConnection.setRequestProperty("Authorization", "Virgil $accessToken")
}
urlConnection.setRequestProperty("Content-Type", "application/json; charset=utf-8")
urlConnection.setRequestProperty(VIRGIL_AGENT_HEADER_KEY, VIRGIL_AGENT_HEADER)
urlConnection.setRequestProperty(VIRGIL_AGENT_HEADER_KEY, virgilAgentHeader)

return urlConnection
}
Expand All @@ -128,7 +140,5 @@ class HttpClient : HttpClientProtocol, Loggable {
private const val VIRGIL_AGENT_HEADER_KEY = "virgil-agent"
private const val VIRGIL_AGENT_PRODUCT = "keyknox"
private const val VIRGIL_AGENT_FAMILY = "jvm"
@JvmStatic private val VIRGIL_AGENT_HEADER =
"$VIRGIL_AGENT_PRODUCT;$VIRGIL_AGENT_FAMILY;${OsUtils.getOsAgentName()};${VersionVirgilAgent.VERSION}"
}
}

0 comments on commit b0abc51

Please sign in to comment.