Skip to content
Permalink
Browse files

Additional convenience features to HttpClient

  • Loading branch information...
darkfrog26 committed Mar 19, 2019
1 parent a5ce599 commit 0d5eaa2d563e87884e3171eae1d303d911ccacc5
Showing with 10 additions and 1 deletion.
  1. +1 −1 build.sbt
  2. +9 −0 client/shared/src/main/scala/io/youi/client/HttpClient.scala
@@ -3,7 +3,7 @@ import sbtcrossproject.CrossPlugin.autoImport.crossProject

name := "youi"
organization in ThisBuild := "io.youi"
version in ThisBuild := "0.10.9"
version in ThisBuild := "0.10.10-SNAPSHOT"
scalaVersion in ThisBuild := "2.12.8"
crossScalaVersions in ThisBuild := List("2.12.8", "2.11.12")
resolvers in ThisBuild += Resolver.sonatypeRepo("releases")
@@ -49,6 +49,11 @@ case class HttpClient(request: HttpRequest,
def post: HttpClient = method(Method.Post)
def header(header: Header): HttpClient = modify(r => r.copy(headers = r.headers.withHeader(header)))
def header(key: String, value: String): HttpClient = header(Header(HeaderKey(key), value))
def headers(headers: Headers, replace: Boolean = false): HttpClient = if (replace) {
modify(_.copy(headers = headers))
} else {
modify(_.copy(headers = request.headers.merge(headers)))
}

def retries(retries: Int): HttpClient = copy(retries = retries)
def sessionManager(sessionManager: SessionManager): HttpClient = copy(sessionManager = Some(sessionManager))
@@ -59,6 +64,10 @@ case class HttpClient(request: HttpRequest,
def noFailOnHttpStatus: HttpClient = failOnHttpStatus(failOnHttpStatus = false)

def content(content: Content): HttpClient = modify(_.copy(content = Some(content)))
def content(content: Option[Content]): HttpClient = content match {
case Some(c) => this.content(c)
case None => this
}
def json(json: Json): HttpClient = content(StringContent(printer.pretty(json), ContentType.`application/json`))

/**

0 comments on commit 0d5eaa2

Please sign in to comment.
You can’t perform that action at this time.