Mime not working after adjusting Request.<< method

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Mime not working after adjusting Request.<< method

getagrip
Hi,
I've adjusted the Request class's << method to be able to post key/value pairs with redundant keys.
One can now use Map or MultiMap to feed Requests:

def <<(values: Map[String, Any]) = next {
  val pairs = new ArrayList[NameValuePair]
  for ((key, value) <- values) {
    value match {
      case set:Set[String] => set foreach (param => pairs.add(new BasicNameValuePair(key, param)))
      case str:String => pairs.add(new BasicNameValuePair(key, str))
    }
  }
  val p = new org.apache.http.client.methods.HttpPost
  p.setEntity(new UrlEncodedFormEntity(pairs, Request.factoryCharset))
  Request.mimic(p) _
}

This works fine as long as I don't chain the << method's together e.g. add a content-stream via Mime after having added a Map.

1. post = request << ("mystream", url, () => stream) << Map("id" -> url)

which yields : error: missing content stream

2. post = request Map("id" -> url) << ("mystream", url, () => stream)

which yields: error: missing id

So obviously the item which is added last via << always wins and the rest gets discarded.

How can I maintain the first-added item in the Request?