aboutsummaryrefslogtreecommitdiff
path: root/mod/src/main/kotlin/moe/nea/ledger/utils/network/RequestTrace.kt
blob: 3953e09c5ce9b249d2c32311b6ab0ecae854695a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package moe.nea.ledger.utils.network

import com.google.gson.JsonElement
import com.google.gson.JsonObject
import moe.nea.ledger.utils.telemetry.ContextValue

class RequestTrace(val request: Request) : ContextValue {
	override fun serialize(): JsonElement {
		return JsonObject().apply {
			addProperty("url", request.url.toString())
			addProperty("method", request.method.name)
			addProperty("content-type", request.headers["content-type"])
			addProperty("accept", request.headers["accept"])
		}
	}

	companion object {
		val KEY = "http_request"
		fun createTrace(request: Request): Pair<String, RequestTrace> = KEY to RequestTrace(request)
	}
}