Skip to content

Commit

Permalink
Merge pull request #46 from Iryna-/uri-enhancement
Browse files Browse the repository at this point in the history
Uri enhancement
  • Loading branch information
adamw committed Nov 14, 2017
2 parents 10d12c4 + 4ef6acc commit 86921e7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion core/src/main/scala/com/softwaremill/sttp/Uri.scala
Original file line number Diff line number Diff line change
@@ -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}

Expand All @@ -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 =
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 86921e7

Please sign in to comment.