Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempting to add headers and add test #797

Merged
merged 13 commits into from
Oct 31, 2024
10 changes: 6 additions & 4 deletions src/main/scala/com/cognite/sdk/scala/v1/Client.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@

package com.cognite.sdk.scala.v1

import com.cognite.scala_sdk.BuildInfo
import cats.implicits._
import cats.{Id, Monad}
import com.cognite.scala_sdk.BuildInfo
import com.cognite.sdk.scala.common._
import com.cognite.sdk.scala.v1.GenericClient.parseResponse
import com.cognite.sdk.scala.v1.resources._
import com.cognite.sdk.scala.v1.resources.fdm.datamodels.{DataModels => DataModelsV3}
import com.cognite.sdk.scala.v1.resources.fdm.containers.Containers
import com.cognite.sdk.scala.v1.resources.fdm.datamodels.{DataModels => DataModelsV3}
import com.cognite.sdk.scala.v1.resources.fdm.instances.Instances
import com.cognite.sdk.scala.v1.resources.fdm.views.Views
import io.circe.Decoder
import io.circe.generic.semiauto.deriveDecoder
import natchez.Trace
import sttp.capabilities.Effect
import sttp.client3._
import sttp.client3.circe.asJsonEither
Expand All @@ -24,7 +25,6 @@ import sttp.monad.MonadError
import java.net.{InetAddress, UnknownHostException}
import scala.concurrent.duration._
import scala.util.control.NonFatal
import natchez.Trace

class TraceSttpBackend[F[_]: Trace, +P](delegate: SttpBackend[F, P]) extends SttpBackend[F, P] {

Expand Down Expand Up @@ -148,9 +148,11 @@ final case class RequestSession[F[_]: Monad: Trace](
.map(_.body)

def head(
uri: Uri
uri: Uri,
overrideHeaders: Seq[Header] = Seq()
): F[Seq[Header]] =
sttpRequest
.headers(overrideHeaders: _*)
.head(uri)
.send(sttpBackend)
.map(_.headers)
Expand Down
14 changes: 6 additions & 8 deletions src/test/scala/com/cognite/sdk/scala/v1/ClientTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@

package com.cognite.sdk.scala.v1

import com.cognite.scala_sdk.BuildInfo

import java.net.{ConnectException, UnknownHostException}
import java.time.Instant
import java.util.Base64
import cats.effect._
import cats.Id
import cats.effect._
import cats.effect.std.Queue
import com.cognite.scala_sdk.BuildInfo
import com.cognite.sdk.scala.common._
import com.cognite.sdk.scala.sttp.{BackpressureThrottleBackend, RateLimitingBackend, RetryingBackend}
import org.scalatest.OptionValues
Expand All @@ -21,9 +17,12 @@ import sttp.client3.{Response, SttpBackend, SttpClientException, UriContext, bas
import sttp.model.{Header, StatusCode}
import sttp.monad.MonadAsyncError

import scala.collection.immutable.Seq
import java.net.{ConnectException, UnknownHostException}
import java.time.Instant
import java.util.Base64
import scala.concurrent.TimeoutException
import scala.concurrent.duration._
import scala.collection.immutable.Seq

@SuppressWarnings(Array("org.wartremover.warts.NonUnitStatements", "org.wartremover.warts.Var"))
class ClientTest extends SdkTestSpec with OptionValues {
Expand Down Expand Up @@ -419,5 +418,4 @@ class ClientTest extends SdkTestSpec with OptionValues {
it should "send a head request and return the headers" in {
client.requestSession.head(uri"https://www.cognite.com/").unsafeRunSync() should not be(empty)
}

}