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
Expand Up @@ -17,7 +17,9 @@ typealias AppId = String

interface AppIdCapable {
companion object {
const val APP_ID_KEY = "CoSec-App-Id"
@Deprecated("Use AppIdCapable.LEGACY_APP_ID_KEY instead.", ReplaceWith("AppIdCapable.LEGACY_APP_ID_KEY"))
const val LEGACY_APP_ID_KEY = "CoSec-App-Id"
const val APP_ID_KEY = "X-App-Id"
}

val appId: AppId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ typealias DeviceId = String

interface DeviceIdCapable {
companion object {
const val DEVICE_ID_KEY = "CoSec-Device-Id"
@Deprecated("Use DeviceIdCapable.DEVICE_ID_KEY instead.", ReplaceWith("DeviceIdCapable.DEVICE_ID_KEY"))
const val LEGACY_DEVICE_ID_KEY = "CoSec-Device-Id"
const val DEVICE_ID_KEY = "X-Device-Id"
}

val deviceId: DeviceId
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ package me.ahoo.cosec.api.context.request

import me.ahoo.cosec.api.context.Attributes
import me.ahoo.cosec.api.context.request.AppIdCapable.Companion.APP_ID_KEY
import me.ahoo.cosec.api.context.request.AppIdCapable.Companion.LEGACY_APP_ID_KEY
import me.ahoo.cosec.api.context.request.DeviceIdCapable.Companion.DEVICE_ID_KEY
import me.ahoo.cosec.api.context.request.DeviceIdCapable.Companion.LEGACY_DEVICE_ID_KEY
import me.ahoo.cosec.api.context.request.RequestIdCapable.Companion.REQUEST_ID_KEY
import me.ahoo.cosec.api.context.request.SpaceIdCapable.Companion.SPACE_ID_KEY
import java.net.URI
Expand All @@ -29,20 +31,31 @@ interface Request :

override val appId: AppId
get() {
return getHeader(APP_ID_KEY).ifBlank { getQuery(APP_ID_KEY) }
return getHeaderOrQuery(APP_ID_KEY, LEGACY_APP_ID_KEY)
}
override val spaceId: SpaceId
get() {
return getHeader(SPACE_ID_KEY).ifBlank { getQuery(SPACE_ID_KEY) }
return getHeaderOrQuery(SPACE_ID_KEY)
}
override val deviceId: DeviceId
get() {
return getHeader(DEVICE_ID_KEY).ifBlank { getQuery(DEVICE_ID_KEY) }
return getHeaderOrQuery(DEVICE_ID_KEY, LEGACY_DEVICE_ID_KEY)
}
override val requestId: RequestId
get() {
return getHeader(REQUEST_ID_KEY)
}

private fun getHeaderOrQuery(key: String, fallbackKey: String): String {
return getHeaderOrQuery(key).ifBlank {
getHeaderOrQuery(fallbackKey)
}
}

private fun getHeaderOrQuery(key: String): String {
return getHeader(key).ifBlank { getQuery(key) }
}

val path: String
val method: String
val remoteIp: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ typealias RequestId = String

interface RequestIdCapable {
companion object {
const val REQUEST_ID_KEY = "CoSec-Request-Id"
@Deprecated("Use RequestIdCapable.REQUEST_ID_KEY instead.", ReplaceWith("RequestIdCapable.REQUEST_ID_KEY"))
const val LEGACY_REQUEST_ID_KEY = "CoSec-Request-Id"
const val REQUEST_ID_KEY = "X-Request-Id"
}

val requestId: RequestId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ typealias SpaceId = String

interface SpaceIdCapable {
companion object {
const val SPACE_ID_KEY = "CoSec-Space-Id"
const val SPACE_ID_KEY = "X-Space-Id"
const val DEFAULT = ""
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ package me.ahoo.cosec.api.context

import me.ahoo.cosec.api.context.request.AppIdCapable
import me.ahoo.cosec.api.context.request.DeviceIdCapable
import me.ahoo.cosec.api.context.request.SpaceIdCapable
import me.ahoo.test.asserts.assert
import org.junit.jupiter.api.Test

class RequestTest {
@Test
fun appIdKey() {
AppIdCapable.APP_ID_KEY.assert().isEqualTo("CoSec-App-Id")
DeviceIdCapable.DEVICE_ID_KEY.assert().isEqualTo("CoSec-Device-Id")
AppIdCapable.LEGACY_APP_ID_KEY.assert().isEqualTo("CoSec-App-Id")
AppIdCapable.APP_ID_KEY.assert().isEqualTo("X-App-Id")
DeviceIdCapable.LEGACY_DEVICE_ID_KEY.assert().isEqualTo("CoSec-Device-Id")
DeviceIdCapable.DEVICE_ID_KEY.assert().isEqualTo("X-Device-Id")
SpaceIdCapable.SPACE_ID_KEY.assert().isEqualTo("X-Space-Id")
}
}
Loading