Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.segment.analytics.kotlin.core

import com.segment.analytics.kotlin.core.Constants.LIBRARY_VERSION
import com.segment.analytics.kotlin.core.utilities.encodeToBase64
import java.io.BufferedReader
import java.io.Closeable
import java.io.IOException
Expand All @@ -12,7 +11,6 @@ import java.net.MalformedURLException
import java.net.URL
import java.util.zip.GZIPOutputStream
class HTTPClient(private val writeKey: String) {
internal val authHeader = authorizationHeader(writeKey)

fun settings(cdnHost: String): Connection {
val connection: HttpURLConnection =
Expand All @@ -29,7 +27,6 @@ class HTTPClient(private val writeKey: String) {
fun upload(apiHost: String): Connection {
val connection: HttpURLConnection = openConnection("https://$apiHost/b")
connection.setRequestProperty("Content-Type", "text/plain")
connection.setRequestProperty("Authorization", authHeader)
connection.doOutput = true
connection.setChunkedStreamingMode(0)
return connection.createPostConnection()
Expand All @@ -56,11 +53,6 @@ class HTTPClient(private val writeKey: String) {
connection.doInput = true
return connection
}

private fun authorizationHeader(writeKey: String): String {
val auth = "$writeKey:"
return "Basic ${encodeToBase64(auth)}"
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.segment.analytics.kotlin.core.utilities.putAll
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
import java.util.*

/**
* Analytics plugin used to populate events with basic context data.
Expand All @@ -18,12 +19,14 @@ class ContextPlugin : Plugin {
override lateinit var analytics: Analytics

private lateinit var library: JsonObject
private val instanceId = UUID.randomUUID().toString()

companion object {
// Library
const val LIBRARY_KEY = "library"
const val LIBRARY_NAME_KEY = "name"
const val LIBRARY_VERSION_KEY = "version"
const val INSTANCE_ID_KEY = "instanceId"
}

override fun setup(analytics: Analytics) {
Expand All @@ -41,6 +44,7 @@ class ContextPlugin : Plugin {

// putLibrary
put(LIBRARY_KEY, library)
put(INSTANCE_ID_KEY, instanceId)
}
event.context = newContext
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class AnalyticsTests {
put(ContextPlugin.LIBRARY_VERSION_KEY, Constants.LIBRARY_VERSION)
}
put(ContextPlugin.LIBRARY_KEY, lib)
put(ContextPlugin.INSTANCE_ID_KEY, "qwerty-qwerty-123")
}

private val testDispatcher = UnconfinedTestDispatcher()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,4 @@ class HTTPClientTests {
}
}

@Test
fun `authHeader is correctly computed`() {
assertEquals("Basic MXZOZ1Vxd0plQ0htcWdJOVMxc09tOVVIQ3lmWXFiYVE6", httpClient.authHeader)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ internal class JavaAnalyticsTest {
put(ContextPlugin.LIBRARY_VERSION_KEY, Constants.LIBRARY_VERSION)
}
put(ContextPlugin.LIBRARY_KEY, lib)
put(ContextPlugin.INSTANCE_ID_KEY, "qwerty-qwerty-123")
}

private val testDispatcher = UnconfinedTestDispatcher()
Expand Down