<<? modifies original request in 0.9

14 views
Skip to first unread message

Tobias G. Pfeiffer

unread,
Feb 3, 2013, 5:06:21 PM2/3/13
to dispatc...@googlegroups.com
Hi,

apparently, the behaviour of <<? changed from 0.8 to 0.9 in the aspect
that in 0.8, "req <<? params" returned a new request with the given
query parameters. In 0.9, it's apparently the *same* request object
with the given parameters set.

scala> val req = url("http://example.com")
req: com.ning.http.client.RequestBuilder =
com.ning.http.client.RequestBuilder@66a008

scala> val reqWithParams1 = req <<? Map("foo" -> "bar")
reqWithParams1: com.ning.http.client.RequestBuilder =
com.ning.http.client.RequestBuilder@66a008

scala> reqWithParams1.url
res0: java.lang.String = http://example.com/?foo=bar

scala> val reqWithParams2 = req <<? Map("some" -> "thing")
reqWithParams2: com.ning.http.client.RequestBuilder =
com.ning.http.client.RequestBuilder@66a008

scala> reqWithParams2.url
res1: java.lang.String = http://example.com/?foo=bar&some=thing

Of course, it is possible to work around that by saying "def" instead of
"val" everywhere, but I think that behaviour is so un-Scala-ish that it
must at least be mentioned in the docs, but IMO it would be even better
if <<? (and related methods) returned a *new* RequestBuilder object.

Kind regards
Tobias
signature.asc

Nathan Hamblen

unread,
Feb 3, 2013, 11:51:23 PM2/3/13
to dispatc...@googlegroups.com
On 02/03/2013 05:06 PM, Tobias G. Pfeiffer wrote:
Of course, it is possible to work around that by saying "def" instead of 
"val" everywhere, but I think that behaviour is so un-Scala-ish that it 
must at least be mentioned in the docs,



 but IMO it would be even better 
if <<? (and related methods) returned a *new* RequestBuilder object.

In my opinion as well, but RequestBuilder in the underlying library does not provide the clone operation that we would need. It's an open source project as well, so anyone could fix that.
https://github.com/AsyncHttpClient/async-http-client

Nathan
Reply all
Reply to author
Forward
0 new messages