diff options
author | Adam Warski <adam@warski.org> | 2017-11-14 11:04:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-14 11:04:24 +0100 |
commit | 86921e7ad0523b67364fc63f2560cef21cb2ced1 (patch) | |
tree | cf71b3b381a9ad33b3c937fcef4e170c39893b3e /core | |
parent | 10d12c47be1a274b9bcbc47c8d2b5068b216bb62 (diff) | |
parent | 4ef6accfd07d13608c5773ed7b79aefa8db55905 (diff) | |
download | sttp-86921e7ad0523b67364fc63f2560cef21cb2ced1.tar.gz sttp-86921e7ad0523b67364fc63f2560cef21cb2ced1.tar.bz2 sttp-86921e7ad0523b67364fc63f2560cef21cb2ced1.zip |
Merge pull request #46 from Iryna-/uri-enhancement
Uri enhancement
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/scala/com/softwaremill/sttp/Uri.scala | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/core/src/main/scala/com/softwaremill/sttp/Uri.scala b/core/src/main/scala/com/softwaremill/sttp/Uri.scala index 9945179..e4d8a8e 100644 --- a/core/src/main/scala/com/softwaremill/sttp/Uri.scala +++ b/core/src/main/scala/com/softwaremill/sttp/Uri.scala @@ -1,7 +1,7 @@ package com.softwaremill.sttp import java.net.URLEncoder - +import java.net.URI import Uri.{QueryFragment, QueryFragmentEncoding, UserInfo} import Uri.QueryFragment.{KeyValue, Plain, Value} @@ -28,6 +28,7 @@ case class Uri(scheme: String, queryFragments: Seq[QueryFragment], fragment: Option[String]) { + def scheme(s: String): Uri = this.copy(scheme = s) def userInfo(username: String): Uri = @@ -193,6 +194,16 @@ object Uri { Uri(scheme, None, host, Some(port), Vector.empty, Vector.empty, None) def apply(scheme: String, host: String, port: Int, path: Seq[String]): Uri = Uri(scheme, None, host, Some(port), path, Vector.empty, None) + def apply(scheme: String, host: String, path: Seq[String]): Uri = + Uri(scheme, None, host, None, path, Vector.empty, None) + def apply(javaUri: URI): Uri = { + val scheme: String = javaUri.getScheme + val host: String = javaUri.getHost + val port: Option[Int] = Option(javaUri.getPort) + val path: Seq[String] = javaUri.getPath.split("/").toList.tail + val fragment: Option[String] = Option(javaUri.getFragment) + Uri(scheme, None, host, port, path, Vector.empty, fragment) + } sealed trait QueryFragment object QueryFragment { |