Skip to content

Commit

Permalink
Extract request and response body by using the charset
Browse files Browse the repository at this point in the history
  • Loading branch information
IshikaDawda committed Nov 19, 2024
1 parent b9cfda2 commit d74f1ff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.newrelic.api.agent.security.schema.exceptions.NewRelicSecurityExcepti
import com.newrelic.api.agent.security.schema.operation.RXSSOperation
import com.newrelic.api.agent.security.schema.policy.AgentPolicy
import com.newrelic.api.agent.security.utils.logging.LogLevel
import fs2.RaiseThrowable
import fs2.text.decodeWithCharset
import org.http4s.Charset.`UTF-8`
import org.http4s.{Headers, Message, Request, Response}
Expand Down Expand Up @@ -113,7 +114,7 @@ object RequestProcessor {
private def extractBody[F[_]: Sync](msg: Message[F]): F[String] = {
if (msg.contentType.nonEmpty && msg.contentType.get.charset.nonEmpty) {
val charset = msg.contentType.get.charset.get;
msg.body.through(decodeWithCharset(charset.nioCharset)).compile.string
msg.bodyText(RaiseThrowable.fromApplicativeError, defaultCharset = charset).compile.string
} else {
msg.bodyText.compile.string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.newrelic.api.agent.security.schema.exceptions.NewRelicSecurityExcepti
import com.newrelic.api.agent.security.schema.operation.RXSSOperation
import com.newrelic.api.agent.security.schema.policy.AgentPolicy
import com.newrelic.api.agent.security.utils.logging.LogLevel
import fs2.RaiseThrowable
import fs2.text.decodeWithCharset
import org.http4s.{Headers, Message, Request, Response}

Expand Down Expand Up @@ -85,7 +86,7 @@ object RequestProcessor {
private def extractBody[F[_]: Sync](msg: Message[F]): F[String] = {
if (msg.contentType.nonEmpty && msg.contentType.get.charset.nonEmpty) {
val charset = msg.contentType.get.charset.get;
msg.body.through(decodeWithCharset(charset.nioCharset)).compile.string
msg.bodyText(RaiseThrowable.fromApplicativeError, defaultCharset = charset).compile.string
} else {
msg.bodyText.compile.string
}
Expand Down

0 comments on commit d74f1ff

Please sign in to comment.