Skip to content

Commit

Permalink
Update scalafmt-core to 3.8.2 (#2211)
Browse files Browse the repository at this point in the history
Co-authored-by: scala-steward <scala-steward>
  • Loading branch information
softwaremill-ci authored Jun 20, 2024
1 parent 33a714b commit ac49b3c
Show file tree
Hide file tree
Showing 24 changed files with 189 additions and 76 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ a5e39d1f4d49c7e32a9b834ebbf429f8f5cab5ee

# Scala Steward: Reformat with scalafmt 3.8.1
19891560efe4b9262b4b4079e5ca95dbbea1a906

# Scala Steward: Reformat with scalafmt 3.8.2
be3cd01c8ea70ee2383d0d05ab8d129f67b70c28
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.8.1
version = 3.8.2
maxColumn = 120
rewrite.rules = [RedundantBraces, RedundantParens, SortImports]
runner.dialect = scala3
1 change: 1 addition & 0 deletions core/src/main/scala/sttp/client4/package.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sttp

package object client4 extends SttpApi {

/** Provide an implicit value of this type to serialize arbitrary classes into a request body. Backends might also
* provide special logic for serializer instances which they define (e.g. to handle streaming).
*/
Expand Down
22 changes: 11 additions & 11 deletions core/src/main/scala/sttp/client4/requestBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,17 @@ trait PartialRequestBuilder[+PR <: PartialRequestBuilder[PR, R], +R]
def followRedirects(fr: Boolean): PR = withOptions(options.copy(followRedirects = fr))

def maxRedirects(n: Int): PR =
if (n <= 0) withOptions(options.copy(followRedirects = false))
else withOptions(options.copy(followRedirects = true, maxRedirects = n))

/** When a POST or PUT request is redirected, should the redirect be a POST/PUT as well (with the original body), or
* should the request be converted to a GET without a body.
*
* Note that this only affects 301 and 302 redirects. 303 redirects are always converted, while 307 and 308
* redirects always keep the same method.
*
* See https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections for details.
*/
if (n <= 0) withOptions(options.copy(followRedirects = false))
else withOptions(options.copy(followRedirects = true, maxRedirects = n))

/** When a POST or PUT request is redirected, should the redirect be a POST/PUT as well (with the original body), or
* should the request be converted to a GET without a body.
*
* Note that this only affects 301 and 302 redirects. 303 redirects are always converted, while 307 and 308 redirects
* always keep the same method.
*
* See https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections for details.
*/
def redirectToGet(r: Boolean): PR = withOptions(options.copy(redirectToGet = r))

def tag(k: String, v: Any): PR = withTags(tags + (k -> v))
Expand Down
16 changes: 8 additions & 8 deletions core/src/main/scala/sttp/client4/testing/ResponseStub.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ object ResponseStub {
}

/** Convenience method to create a Response instance, mainly useful in tests using
* [[sttp.client4.testing.BackendStub]] and partial matchers.
*/
* [[sttp.client4.testing.BackendStub]] and partial matchers.
*/
def apply[T](body: T, code: StatusCode): Response[T] =
Response(body, code, resolveStatusText(code), Nil, Nil, emptyGet)

/** Convenience method to create a Response instance, mainly useful in tests using
* [[sttp.client4.testing.BackendStub]] and partial matchers.
*/
* [[sttp.client4.testing.BackendStub]] and partial matchers.
*/
def apply[T](body: T, code: StatusCode, statusText: String): Response[T] =
Response(body, code, resolveStatusText(code, statusText), Nil, Nil, emptyGet)

/** Convenience method to create a Response instance, mainly useful in tests using
* [[sttp.client4.testing.BackendStub]] and partial matchers.
*/
* [[sttp.client4.testing.BackendStub]] and partial matchers.
*/
def apply[T](body: T, code: StatusCode, statusText: String, headers: Seq[Header]): Response[T] =
Response(body, code, resolveStatusText(code, statusText), headers, Nil, emptyGet)

/** Convenience method to create a Response instance, mainly useful in tests using
* [[sttp.client4.testing.BackendStub]] and partial matchers.
*/
* [[sttp.client4.testing.BackendStub]] and partial matchers.
*/
def ok[T](body: T): Response[T] = apply(body, StatusCode.Ok)

private def resolveStatusText(statusCode: StatusCode, provided: String = ""): String =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
package sttp.client4.wrappers

import sttp.capabilities.Effect
import sttp.client4.{Backend, GenericBackend, GenericRequest, Response, StreamBackend, SyncBackend, WebSocketBackend, WebSocketStreamBackend}
import sttp.client4.{
Backend,
GenericBackend,
GenericRequest,
Response,
StreamBackend,
SyncBackend,
WebSocketBackend,
WebSocketStreamBackend
}
import sttp.model.Uri
import sttp.monad.syntax._
import sttp.shared.Identity
Expand Down
9 changes: 8 additions & 1 deletion core/src/main/scala/sttp/client4/wrappers/TryBackend.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package sttp.client4.wrappers

import sttp.client4.monad.FunctionK
import sttp.client4.{Backend, StreamBackend, SyncBackend, WebSocketBackend, WebSocketStreamBackend, WebSocketSyncBackend}
import sttp.client4.{
Backend,
StreamBackend,
SyncBackend,
WebSocketBackend,
WebSocketStreamBackend,
WebSocketSyncBackend
}
import sttp.monad.TryMonad
import sttp.shared.Identity

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import sttp.client4.httpclient.HttpClientBackend.EncodingHandler
import sttp.client4.httpclient.HttpClientSyncBackend.SyncEncodingHandler
import sttp.client4.internal.httpclient._
import sttp.client4.internal.ws.{SimpleQueue, SyncQueue, WebSocketEvent}
import sttp.client4.internal.{NoStreams, emptyInputStream}
import sttp.client4.internal.{emptyInputStream, NoStreams}
import sttp.client4.testing.WebSocketSyncBackendStub
import sttp.client4.{BackendOptions, GenericRequest, Response, WebSocketSyncBackend, wrappers}
import sttp.client4.{wrappers, BackendOptions, GenericRequest, Response, WebSocketSyncBackend}
import sttp.model.StatusCode
import sttp.monad.{IdentityMonad, MonadError}
import sttp.shared.Identity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,25 @@ import sttp.client4.httpurlconnection.HttpURLConnectionBackend.EncodingHandler
import sttp.client4.internal._
import sttp.client4.testing.SyncBackendStub
import sttp.client4.ws.{GotAWebSocketException, NotAWebSocketException}
import sttp.client4.{BackendOptions, BasicBodyPart, BasicMultipartBody, ByteArrayBody, ByteBufferBody, FileBody, GenericRequest, GenericWebSocketResponseAs, InputStreamBody, MultipartStreamBody, NoBody, Response, StreamBody, StringBody, SttpClientException, SyncBackend, wrappers}
import sttp.client4.{
wrappers,
BackendOptions,
BasicBodyPart,
BasicMultipartBody,
ByteArrayBody,
ByteBufferBody,
FileBody,
GenericRequest,
GenericWebSocketResponseAs,
InputStreamBody,
MultipartStreamBody,
NoBody,
Response,
StreamBody,
StringBody,
SttpClientException,
SyncBackend
}
import sttp.model._
import sttp.monad.{IdentityMonad, MonadError}
import sttp.shared.Identity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ class BackendStubTests extends AnyFlatSpec with Matchers with ScalaFutures {
.thenRespondF(ResponseStub(Right("OK from monad"), StatusCode.Ok, "OK"))
.whenRequestMatches(_.uri.port.exists(_ == 8081))
.thenRespondF(r =>
ResponseStub(Right(s"OK from request. Request was sent to host: ${r.uri.host.getOrElse("?")}"), StatusCode.Ok, "OK")
ResponseStub(
Right(s"OK from request. Request was sent to host: ${r.uri.host.getOrElse("?")}"),
StatusCode.Ok,
"OK"
)
)
.whenRequestMatches(r => r.uri.path.contains("metadata") && r.method == Method.POST)
.thenRespondOk()
Expand Down
1 change: 0 additions & 1 deletion core/src/test/scala/sttp/client4/testing/HttpTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ trait HttpTest[F[_]]
"multipart" - {
def mp = basicRequest.post(uri"$endpoint/multipart").response(asStringAlways)


"not encode tilde" in {
val part = multipart("v1", Map("k1" -> "v1~", "~k2" -> "v2"))
part.body.show should be("string: k1=v1~&~k2=v2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ trait SyncHttpTest
.get(uri"$endpoint/timeout")
.readTimeout(200.milliseconds)
.response(asString)
val caught = intercept[RuntimeException] { req.send(backend) }
val caught = intercept[RuntimeException](req.send(backend))
caught.getMessage should include("TIMEDOUT")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class OxServerSentEventsTest extends AnyFlatSpec with Matchers with BeforeAndAft
.post(uri"$endpoint/sse/echo3")
.body(sseData)
.response(asInputStreamAlways { is =>
OxServerSentEvents.parse(is).take(3).toList shouldBe(expectedEvents)
OxServerSentEvents.parse(is).take(3).toList shouldBe expectedEvents
()
})
.send(backend)
}

override protected def afterAll(): Unit =
backend.close()
super.afterAll()
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class OxWebSocketTest extends AnyFlatSpec with BeforeAndAfterAll with Matchers w
.thenRespond {
case WebSocketFrame.Pong(payload) if new String(payload) == "test-ping" =>
List(WebSocketFrame.text("test"))
case other =>
case other =>
fail(s"Unexpected frame: $other")
},
StatusCode.SwitchingProtocols
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import sttp.client4._
import sttp.client4.impl.zio._
import sttp.client4.testing.{BackendStub, RawStream, StreamBackendStub, ResponseStub, TestStreams}
import sttp.client4.testing.{BackendStub, RawStream, ResponseStub, StreamBackendStub, TestStreams}
import sttp.model.Method
import zio.stream.ZStream
import zio.{Task, ZIO}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import sttp.client4.testing.SyncBackendStub
import sttp.model.Uri
import org.json4s.{DefaultFormats, native}
import org.json4s.{native, DefaultFormats}

case class Person(name: String)

Expand Down
2 changes: 1 addition & 1 deletion json/json4s/src/test/scala/sttp/client4/Json4sTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package sttp.client4
import org.json4s.JsonAST.JString
import org.json4s.ParserUtil.ParseException
import org.json4s.native.Serialization
import org.json4s.{DefaultFormats, JField, JObject, MappingException, native}
import org.json4s.{native, DefaultFormats, JField, JObject, MappingException}
import org.scalatest._
import sttp.client4.internal._
import sttp.model._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object OpenTelemetryMetricsBackend {
Metrics names and model for Open Telemetry is based on these two specifications:
https://opentelemetry.io/docs/specs/semconv/http/http-metrics/#http-client
https://github.com/open-telemetry/opentelemetry-specification/blob/v1.31.0/specification/metrics/api.md#instrument
* */
* */
val DefaultLatencyHistogramName = "http.client.request.duration"
val DefaultRequestSizeHistogramName = "http.client.request.size.bytes"
val DefaultResponseSizeHistogramName = "http.client.response.size.bytes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@ object OpenTelemetryMetricsConfig {
openTelemetry: OpenTelemetry,
meterConfig: MeterConfig = MeterConfig.Default,
clock: Clock = Clock.systemUTC(),
requestToLatencyHistogramMapper: GenericRequest[_, _] => Option[HistogramCollectorConfig] = (_: GenericRequest[_, _]) =>
Some(HistogramCollectorConfig(DefaultLatencyHistogramName, buckets = HistogramCollectorConfig.DefaultLatencyBuckets, unit = HistogramCollectorConfig.Milliseconds)),
requestToLatencyHistogramMapper: GenericRequest[_, _] => Option[HistogramCollectorConfig] =
(_: GenericRequest[_, _]) =>
Some(
HistogramCollectorConfig(
DefaultLatencyHistogramName,
buckets = HistogramCollectorConfig.DefaultLatencyBuckets,
unit = HistogramCollectorConfig.Milliseconds
)
),
requestToInProgressCounterMapper: GenericRequest[_, _] => Option[CollectorConfig] = (_: GenericRequest[_, _]) =>
Some(CollectorConfig(DefaultRequestsActiveCounterName)),
responseToSuccessCounterMapper: Response[_] => Option[CollectorConfig] = (_: Response[_]) =>
Expand All @@ -34,10 +41,23 @@ object OpenTelemetryMetricsConfig {
Some(CollectorConfig(DefaultErrorCounterName)),
requestToFailureCounterMapper: (GenericRequest[_, _], Throwable) => Option[CollectorConfig] =
(_: GenericRequest[_, _], _: Throwable) => Some(CollectorConfig(DefaultFailureCounterName)),
requestToSizeHistogramMapper: GenericRequest[_, _] => Option[HistogramCollectorConfig] = (_: GenericRequest[_, _]) =>
Some(HistogramCollectorConfig(DefaultRequestSizeHistogramName, buckets = HistogramCollectorConfig.DefaultSizeBuckets, unit = HistogramCollectorConfig.Bytes)),
requestToSizeHistogramMapper: GenericRequest[_, _] => Option[HistogramCollectorConfig] =
(_: GenericRequest[_, _]) =>
Some(
HistogramCollectorConfig(
DefaultRequestSizeHistogramName,
buckets = HistogramCollectorConfig.DefaultSizeBuckets,
unit = HistogramCollectorConfig.Bytes
)
),
responseToSizeHistogramMapper: Response[_] => Option[HistogramCollectorConfig] = (_: Response[_]) =>
Some(HistogramCollectorConfig(DefaultResponseSizeHistogramName, buckets = HistogramCollectorConfig.DefaultSizeBuckets, unit = HistogramCollectorConfig.Bytes)),
Some(
HistogramCollectorConfig(
DefaultResponseSizeHistogramName,
buckets = HistogramCollectorConfig.DefaultSizeBuckets,
unit = HistogramCollectorConfig.Bytes
)
),
): OpenTelemetryMetricsConfig = usingMeter(
openTelemetry.meterBuilder(meterConfig.name).setInstrumentationVersion(meterConfig.version).build(),
clock,
Expand All @@ -53,8 +73,15 @@ object OpenTelemetryMetricsConfig {
def usingMeter(
meter: Meter,
clock: Clock = Clock.systemUTC(),
requestToLatencyHistogramMapper: GenericRequest[_, _] => Option[HistogramCollectorConfig] = (_: GenericRequest[_, _]) =>
Some(HistogramCollectorConfig(DefaultLatencyHistogramName, buckets = HistogramCollectorConfig.DefaultLatencyBuckets, unit = HistogramCollectorConfig.Milliseconds)),
requestToLatencyHistogramMapper: GenericRequest[_, _] => Option[HistogramCollectorConfig] =
(_: GenericRequest[_, _]) =>
Some(
HistogramCollectorConfig(
DefaultLatencyHistogramName,
buckets = HistogramCollectorConfig.DefaultLatencyBuckets,
unit = HistogramCollectorConfig.Milliseconds
)
),
requestToInProgressCounterMapper: GenericRequest[_, _] => Option[CollectorConfig] = (_: GenericRequest[_, _]) =>
Some(CollectorConfig(DefaultRequestsActiveCounterName)),
responseToSuccessCounterMapper: Response[_] => Option[CollectorConfig] = (_: Response[_]) =>
Expand All @@ -63,10 +90,23 @@ object OpenTelemetryMetricsConfig {
Some(CollectorConfig(DefaultErrorCounterName)),
requestToFailureCounterMapper: (GenericRequest[_, _], Throwable) => Option[CollectorConfig] =
(_: GenericRequest[_, _], _: Throwable) => Some(CollectorConfig(DefaultFailureCounterName)),
requestToSizeHistogramMapper: GenericRequest[_, _] => Option[HistogramCollectorConfig] = (_: GenericRequest[_, _]) =>
Some(HistogramCollectorConfig(DefaultRequestSizeHistogramName, buckets = HistogramCollectorConfig.DefaultSizeBuckets, unit = HistogramCollectorConfig.Bytes)),
requestToSizeHistogramMapper: GenericRequest[_, _] => Option[HistogramCollectorConfig] =
(_: GenericRequest[_, _]) =>
Some(
HistogramCollectorConfig(
DefaultRequestSizeHistogramName,
buckets = HistogramCollectorConfig.DefaultSizeBuckets,
unit = HistogramCollectorConfig.Bytes
)
),
responseToSizeHistogramMapper: Response[_] => Option[HistogramCollectorConfig] = (_: Response[_]) =>
Some(HistogramCollectorConfig(DefaultResponseSizeHistogramName, buckets = HistogramCollectorConfig.DefaultSizeBuckets, unit = HistogramCollectorConfig.Bytes))
Some(
HistogramCollectorConfig(
DefaultResponseSizeHistogramName,
buckets = HistogramCollectorConfig.DefaultSizeBuckets,
unit = HistogramCollectorConfig.Bytes
)
)
): OpenTelemetryMetricsConfig =
OpenTelemetryMetricsConfig(
meter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.scalatest.OptionValues
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import sttp.client4.testing.{ResponseStub, SyncBackendStub}
import sttp.client4.{DeserializationException, SttpClientException, UriContext, asString, basicRequest}
import sttp.client4.{asString, basicRequest, DeserializationException, SttpClientException, UriContext}
import sttp.model.{Header, StatusCode}

import scala.collection.JavaConverters._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import sttp.client4.impl.zio.{RIOMonadAsyncError, ZioTestBase}
import sttp.client4.testing.{BackendStub, ResponseStub}
import sttp.client4.{Backend, GenericRequest, Response, UriContext, basicRequest}
import sttp.client4.{basicRequest, Backend, GenericRequest, Response, UriContext}
import sttp.model.StatusCode
import zio.{Runtime, Task, Unsafe, ZIO}
import zio.telemetry.opentelemetry.Tracing
Expand Down
Loading

0 comments on commit ac49b3c

Please sign in to comment.