Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
benjben committed Aug 16, 2023
1 parent f078371 commit 76a3474
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Service[F[_]: Sync](
appInfo: AppInfo
) extends IService[F] {

val pixelStream = Stream.iterable[F, Byte](CollectorService.pixel)
val pixelStream = Stream.iterable[F, Byte](Service.pixel)

private val collector = s"${appInfo.name}:${appInfo.version}"

Expand All @@ -65,15 +65,15 @@ class Service[F[_]: Sync](
): F[Response[F]] =
for {
body <- body
hostname = extractHostname(request)
userAgent = extractHeader(request, "User-Agent")
refererUri = extractHeader(request, "Referer")
spAnonymous = extractHeader(request, "SP-Anonymous")
ip = extractIp(request, spAnonymous)
queryString = Some(request.queryString)
cookie = extractCookie(request)
nuidOpt = networkUserId(request, cookie, spAnonymous)
nuid = nuidOpt.getOrElse(UUID.randomUUID().toString)
hostname = extractHostname(request)
userAgent = extractHeader(request, "User-Agent")
refererUri = extractHeader(request, "Referer")
spAnonymous = extractHeader(request, "SP-Anonymous")
ip = extractIp(request, spAnonymous)
queryString = Some(request.queryString)
cookie = extractCookie(request)
nuidOpt = networkUserId(request, cookie, spAnonymous)
nuid = nuidOpt.getOrElse(UUID.randomUUID().toString)
(ipAddress, partitionKey) = ipAndPartitionKey(ip, config.streams.useIpAddressAsPartitionKey)
event = buildEvent(
queryString,
Expand Down Expand Up @@ -127,7 +127,7 @@ class Service[F[_]: Sync](
req.headers.get(CIString(headerName)).map(_.head.value)

def extractCookie(req: Request[F]): Option[RequestCookie] =
config.cookieConfig.flatMap(c => req.cookies.find(_.name == c.name))
req.cookies.find(_.name == config.cookie.name)

def extractHostname(req: Request[F]): Option[String] =
req.uri.authority.map(_.host.renderString) // Hostname is extracted like this in Akka-Http as well
Expand Down Expand Up @@ -349,7 +349,7 @@ class Service[F[_]: Sync](
spAnonymous: Option[String]
): Option[String] =
spAnonymous match {
case Some(_) => Some(CollectorService.spAnonymousNuid)
case Some(_) => Some(Service.spAnonymousNuid)
case None => request.uri.query.params.get("nuid").orElse(requestCookie.map(_.content))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class ServiceSpec extends Specification {
headers = Headers(
Header.Raw(ci"SP-Anonymous", "*")
)
).addCookie(TestUtils.testConf.cookie.name, nuid)
).addCookie(TestUtils.testConfig.cookie.name, nuid)
val r = service
.cookie(
body = IO.pure(Some("b")),
Expand All @@ -117,7 +117,7 @@ class ServiceSpec extends Specification {
val nuid = "test-nuid"
val req = Request[IO](
method = Method.POST
).addCookie(TestUtils.testConf.cookie.name, nuid)
).addCookie(TestUtils.testConfig.cookie.name, nuid)
val r = service
.cookie(
body = IO.pure(Some("b")),
Expand Down Expand Up @@ -221,7 +221,7 @@ class ServiceSpec extends Specification {
query = Query.unsafeFromString("a=b"),
authority = Some(Uri.Authority(host = Uri.RegName("example.com")))
)
).withAttribute(Request.Keys.ConnectionInfo, testConnection).addCookie(TestUtils.testConf.cookie.name, nuid)
).withAttribute(Request.Keys.ConnectionInfo, testConnection).addCookie(TestUtils.testConfig.cookie.name, nuid)
val r = service
.cookie(
body = IO.pure(Some("b")),
Expand Down

0 comments on commit 76a3474

Please sign in to comment.