Skip to content

Commit

Permalink
Additional convenience features to HttpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Mar 19, 2019
1 parent a5ce599 commit 0d5eaa2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.sbt
Expand Up @@ -3,7 +3,7 @@ import sbtcrossproject.CrossPlugin.autoImport.crossProject


name := "youi" name := "youi"
organization in ThisBuild := "io.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" scalaVersion in ThisBuild := "2.12.8"
crossScalaVersions in ThisBuild := List("2.12.8", "2.11.12") crossScalaVersions in ThisBuild := List("2.12.8", "2.11.12")
resolvers in ThisBuild += Resolver.sonatypeRepo("releases") resolvers in ThisBuild += Resolver.sonatypeRepo("releases")
Expand Down
9 changes: 9 additions & 0 deletions client/shared/src/main/scala/io/youi/client/HttpClient.scala
Expand Up @@ -49,6 +49,11 @@ case class HttpClient(request: HttpRequest,
def post: HttpClient = method(Method.Post) def post: HttpClient = method(Method.Post)
def header(header: Header): HttpClient = modify(r => r.copy(headers = r.headers.withHeader(header))) 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 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 retries(retries: Int): HttpClient = copy(retries = retries)
def sessionManager(sessionManager: SessionManager): HttpClient = copy(sessionManager = Some(sessionManager)) def sessionManager(sessionManager: SessionManager): HttpClient = copy(sessionManager = Some(sessionManager))
Expand All @@ -59,6 +64,10 @@ case class HttpClient(request: HttpRequest,
def noFailOnHttpStatus: HttpClient = failOnHttpStatus(failOnHttpStatus = false) def noFailOnHttpStatus: HttpClient = failOnHttpStatus(failOnHttpStatus = false)


def content(content: Content): HttpClient = modify(_.copy(content = Some(content))) 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`)) def json(json: Json): HttpClient = content(StringContent(printer.pretty(json), ContentType.`application/json`))


/** /**
Expand Down

0 comments on commit 0d5eaa2

Please sign in to comment.