Creating a new HTTP host

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Creating a new HTTP host

pr1001
This isn't a bug per-se in Dispatch but I thought I'd bring it up here because I found it when using Dispatch. Consider this:

scala> `:/`("http://test").host
res0: Option[org.apache.http.HttpHost] = Some(http://http://test)

The culprit is org.apache.http.HttpHost. For example:

scala> new HttpHost("http://test")
res1: org.apache.http.HttpHost = http://http://test

Might Dispatch do a sanity check to work around this? Here's the quick hack I whipped up for my own code:

if (apiUrl startsWith "http://") {
  :/(apiUrl.drop(7))
} else if (apiUrl startsWith "https://") {
  :/(apiUrl.drop(8)).secure
} else {
  :/(apiUrl)
}

Cheers,
Peter
Reply | Threaded
Open this post in threaded view
|

Re: Creating a new HTTP host

n8han
Administrator
On 03/07/2011 11:05 AM, pr1001 [via Databinder] wrote:
[...]

Might Dispatch do a sanity check to work around this? Here's the quick hack I whipped up for my own code:

I'd be afraid the cure would cause even more unexpected behavior. I think there are a few problems at the root of this.

1. Dispatch doesn't have an explicit way use URL strings, it just has that implicit conversion from String to Request. I find I almost never use that conversion.

2. Dispatch doesn't have a lot of useful examples and tutorials. Bad Dispatch.

3. Maybe Apache's HttpHost should be throwing an exception on slashes and such. Or maybe not--those guys are pretty hard core about following relevant specs.

I can probably come up with something nice for 1 if people want it.

https://github.com/n8han/databinder-dispatch/issues

Nathan
Reply | Threaded
Open this post in threaded view
|

Re: Creating a new HTTP host

pr1001
Sure, making the implicit conversion a little nicer, perhaps using the logic I put would be nice. Also, just putting a note in the source code would be handy.

Thanks,
Peter