Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/src/main/scala/sttp/model/Header.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ object Header {
def accept(mediaType: MediaType, additionalMediaTypes: MediaType*): Header = accept(
s"${(mediaType :: additionalMediaTypes.toList).map(_.noCharset).mkString(", ")}"
)
def acceptQuery(mediaType: MediaType, additionalMediaTypes: MediaType*): Header = acceptQuery(
s"${(mediaType :: additionalMediaTypes.toList).map(_.toString).mkString(", ")}"
)
def accept(mediaRanges: String): Header = Header(HeaderNames.Accept, mediaRanges)
def acceptQuery(mediaRanges: String): Header = Header(HeaderNames.AcceptQuery, mediaRanges)
def acceptCharset(charsetRanges: String): Header = Header(HeaderNames.AcceptCharset, charsetRanges)
def acceptEncoding(encodingRanges: String): Header = Header(HeaderNames.AcceptEncoding, encodingRanges)
def accessControlAllowCredentials(allow: Boolean): Header =
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/scala/sttp/model/HeaderNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ trait HeaderNames {
val AcceptEncoding = "Accept-Encoding"
val AcceptLanguage = "Accept-Language"
val AcceptRanges = "Accept-Ranges"
// a def, not a val, as adding a val to a trait breaks binary compatibility for classes implementing it
def AcceptQuery: String = "Accept-Query"
val AccessControlAllowCredentials = "Access-Control-Allow-Credentials"
val AccessControlAllowHeaders = "Access-Control-Allow-Headers"
val AccessControlAllowMethods = "Access-Control-Allow-Methods"
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/scala/sttp/model/Method.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ object Method extends Methods {
def isSafe(m: Method): Boolean = safe.contains(m)

private val idempotent: Set[Method] =
Set(Method.HEAD, Method.TRACE, Method.GET, Method.PUT, Method.OPTIONS, Method.DELETE)
private val safe: Set[Method] = Set(Method.HEAD, Method.GET, Method.OPTIONS)
Set(Method.HEAD, Method.TRACE, Method.GET, Method.PUT, Method.OPTIONS, Method.DELETE, Method.QUERY)
private val safe: Set[Method] = Set(Method.HEAD, Method.GET, Method.OPTIONS, Method.QUERY)
}

trait Methods {
Expand All @@ -42,6 +42,8 @@ trait Methods {
val POST: Method = Method("POST")
val PUT: Method = Method("PUT")
val DELETE: Method = Method("DELETE")
// a def, not a val, as adding a val to a trait breaks binary compatibility for classes implementing it
def QUERY: Method = Method("QUERY")
val OPTIONS: Method = Method("OPTIONS")
val PATCH: Method = Method("PATCH")
val CONNECT: Method = Method("CONNECT")
Expand Down
1 change: 1 addition & 0 deletions core/src/test/scala/sttp/model/MethodTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ class MethodTest extends AnyFlatSpec with Matchers {
Method.unsafeApply("patch") shouldBe Method.unsafeApply("PATCH")
Method.unsafeApply("connect") shouldBe Method.unsafeApply("CONNECT")
Method.unsafeApply("trace") shouldBe Method.unsafeApply("TRACE")
Method.unsafeApply("query") shouldBe Method.unsafeApply("QUERY")
}
}
7 changes: 7 additions & 0 deletions core/src/test/scalajvm/sttp/model/HeaderTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class HeaderTests extends AnyFlatSpec with Matchers {
.toString shouldBe "Cache-Control: no-transform, public, s-maxage=10"
}

it should "properly create an accept-query header" in {
Header
.acceptQuery(MediaType.ApplicationJson, MediaType.ApplicationXml)
.toString shouldBe "Accept-Query: application/json, application/xml"
Header.acceptQuery("application/jsonpath").toString shouldBe "Accept-Query: application/jsonpath"
}

"Instant" should "be formatted according to rfc1123-date1 with a leading zero for single-digit dates" in {
Header.toHttpDateString(rfc1123DatetimeToBeChecked) shouldBe rfc1123DatetimeFormatted
}
Expand Down
Loading