Skip to content

Better default host/port/protocol when running in browser #81

@lj-ditrapani

Description

@lj-ditrapani

Hello,

I like this library, thanks for creating it!

When running in the browser, would it be reasonable to provide default HttpRequest parameter values based off of document.location if the user does not specify host, port and/or protocol? For example, I find myself writing this code whenever I use roshttp on the client side to make requests back the originating server.

  import roshttp.{HttpRequest, Protocol}

  val baseRequest: HttpRequest = {
    val hostPort: Array[String] = document.location.host.split(":")
    val host: String = hostPort(0)
    val request1 = HttpRequest().withHost(host)
    val request2 =
      if (hostPort.length > 1) {
        request1.withPort(hostPort(1).toInt)
      } else {
        request1
      }
    if (document.location.protocol == "https:") {
      request2.withProtocol(Protocol.HTTPS)
    } else {
      request2
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions