Skip to content

Commit 0fb7de8

Browse files
jakehschwartzfarmdawgnation
authored andcommitted
Use properties to track if methodExplicitlySet
1 parent 10f56fb commit 0fb7de8

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

core/src/main/scala/requests.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ case class Req(
6363
}
6464

6565
object Req {
66-
final case class Properties(bodyType: BodyType = NoBody)
66+
final case class Properties(bodyType: BodyType = NoBody, methodExplicitlySet: Boolean = false)
6767

6868
trait BodyType
6969
final case object NoBody extends BodyType
@@ -409,21 +409,18 @@ trait RequestBuilderVerbs extends RequestVerbs {
409409
) }
410410
}
411411

412-
private[this] var methodExplicitlySet: Boolean = false
413-
414412
/**
415413
* Explicitly set the method of the request.
416414
*/
417415
def setMethod(method: String) = {
418-
methodExplicitlySet = true
419-
subject.underlying(_.setMethod(method))
416+
subject.underlying(_.setMethod(method), _.copy(methodExplicitlySet = true))
420417
}
421418

422419
/**
423420
* Set method unless method has been explicitly set using [[setMethod]].
424421
*/
425422
def implyMethod(method: String) = {
426-
if (! methodExplicitlySet) {
423+
if (!subject.props.methodExplicitlySet) {
427424
subject.underlying(_.setMethod(method))
428425
} else {
429426
subject

core/src/test/scala/basic.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ with DispatchCleanup {
9696
res() ?= ("POST" + sample)
9797
}
9898

99+
property("PUT alphaString body with setBody and get response") = forAll(Gen.alphaStr) { (sample: String) =>
100+
val res = Http.default(
101+
(localhost / "echobody").PUT.setBody(sample) > as.String
102+
)
103+
res() ?= ("PUT" + sample)
104+
}
105+
106+
property("PUT alphaString body with << and get response") = forAll(Gen.alphaStr) { (sample: String) =>
107+
val res = Http.default(
108+
(localhost / "echobody").PUT << sample > as.String
109+
)
110+
res() ?= ("PUT" + sample)
111+
}
112+
99113
property("GET and handle") = forAll(Gen.alphaStr) { (sample: String) =>
100114
val res = Http.default(
101115
localhost / "echo" <<? Map("echo" -> sample) > as.String

0 commit comments

Comments
 (0)