File tree Expand file tree Collapse file tree 5 files changed +24
-0
lines changed
cli/src/commonMain/kotlin/utils
core/src/main/kotlin/plugins
utils/system/src/commonMain/kotlin Expand file tree Collapse file tree 5 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import io.ktor.client.plugins.auth.Auth
2424import io.ktor.client.plugins.auth.providers.BearerTokens
2525import io.ktor.client.plugins.auth.providers.bearer
2626import io.ktor.client.plugins.defaultRequest
27+ import io.ktor.client.request.header
2728
2829import org.eclipse.apoapsis.ortserver.cli.COMMAND_NAME
2930import org.eclipse.apoapsis.ortserver.cli.model.AuthenticationStorage
@@ -35,6 +36,7 @@ import org.eclipse.apoapsis.ortserver.client.auth.AuthService
3536import org.eclipse.apoapsis.ortserver.client.auth.AuthenticationException
3637import org.eclipse.apoapsis.ortserver.client.createDefaultHttpClient
3738import org.eclipse.apoapsis.ortserver.client.createOrtHttpClient
39+ import org.eclipse.apoapsis.ortserver.utils.system.CustomHttpHeaders
3840
3941/* *
4042 * Create an authenticated ORT Server client using the stored authentication. Returns null if the user is not
@@ -53,6 +55,7 @@ fun createUnauthenticatedOrtServerClient(baseUrl: String) = OrtServerClient(crea
5355private fun createHttpClient (url : String ) = createOrtHttpClient(JSON ) {
5456 defaultRequest {
5557 url(url)
58+ header(CustomHttpHeaders .ClientType , " ort-server-cli" )
5659 }
5760}
5861
Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ import io.ktor.server.config.ApplicationConfig
2727import io.ktor.server.plugins.cors.routing.CORS
2828import io.ktor.server.plugins.defaultheaders.DefaultHeaders
2929
30+ import org.eclipse.apoapsis.ortserver.utils.system.CustomHttpHeaders
31+
3032import org.koin.ktor.ext.inject
3133
3234fun Application.configureHTTP () {
@@ -39,6 +41,7 @@ fun Application.configureHTTP() {
3941 install(CORS ) {
4042 allowedHosts.split(' ,' ).forEach(::allowHost)
4143 allowCredentials = true
44+ allowHeader(CustomHttpHeaders .ClientType )
4245 allowHeader(HttpHeaders .Authorization )
4346 allowHeader(HttpHeaders .ContentType )
4447 allowMethod(HttpMethod .Delete )
Original file line number Diff line number Diff line change 1919
2020package org.eclipse.apoapsis.ortserver.core.plugins
2121
22+ import io.ktor.http.HttpHeaders
2223import io.ktor.server.application.Application
2324import io.ktor.server.application.install
2425import io.ktor.server.plugins.calllogging.CallLogging
2526import io.ktor.server.request.path
2627
2728import java.util.UUID
2829
30+ import org.eclipse.apoapsis.ortserver.utils.system.CustomHttpHeaders
31+
2932import org.slf4j.event.Level
3033
3134fun Application.configureMonitoring () {
@@ -42,5 +45,10 @@ fun Application.configureMonitoring() {
4245 mdc(" organizationId" ) { it.parameters[" organizationId" ] }
4346 mdc(" productId" ) { it.parameters[" productId" ] }
4447 mdc(" repositoryId" ) { it.parameters[" repositoryId" ] }
48+ mdc(" clientType" ) { call ->
49+ call.request.headers[CustomHttpHeaders .ClientType ]
50+ ? : call.request.headers[HttpHeaders .UserAgent ]
51+ ? : " unknown"
52+ }
4553 }
4654}
Original file line number Diff line number Diff line change @@ -40,6 +40,9 @@ import { routeTree } from '@/routeTree.gen';
4040client . setConfig ( {
4141 baseURL : config . API_URL ,
4242 auth : ( ) => authRef . current ?. user ?. access_token ,
43+ headers : {
44+ 'X-Client-Type' : 'ort-server-ui' ,
45+ } ,
4346} ) ;
4447
4548export interface RouterContext {
Original file line number Diff line number Diff line change @@ -23,3 +23,10 @@ package org.eclipse.apoapsis.ortserver.utils.system
2323 * The version of the ORT Server as a string.
2424 */
2525const val ORT_SERVER_VERSION = BuildConfig .ORT_SERVER_VERSION
26+
27+ object CustomHttpHeaders {
28+ /* *
29+ * HTTP header name used to identify the client type making API requests.
30+ */
31+ const val ClientType = " X-Client-Type"
32+ }
You can’t perform that action at this time.
0 commit comments