String
to String
for HTTP exchangesThis structure differs from Map
as each key can have multiple associations
and the order of insertion is important to some services.
curl :: HeaderMap :: defaultinit
curl :: HeaderMap :: join_pairs
Concatenate couple of 'key value' separated by 'sep' in Arraycurl :: HeaderMap :: to_url_encoded
Getself
as a single string for HTTP POST
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
curl :: HeaderMap :: defaultinit
core :: Object :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
curl :: HeaderMap :: join_pairs
Concatenate couple of 'key value' separated by 'sep' in Arraycore :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).curl :: HeaderMap :: to_url_encoded
Getself
as a single string for HTTP POST
# Pseudo map associating `String` to `String` for HTTP exchanges
#
# This structure differs from `Map` as each key can have multiple associations
# and the order of insertion is important to some services.
class HeaderMap
private var array = new Array[Couple[String, String]]
# Add a `value` associated to `key`
fun []=(key, value: String)
do
array.add new Couple[String, String](key, value)
end
# Get a list of the keys associated to `key`
fun [](k: String): Array[String]
do
var res = new Array[String]
for c in array do if c.first == k then res.add c.second
return res
end
# Iterate over all the associations in `self`
fun iterator: MapIterator[String, String] do return new HeaderMapIterator(self)
# Get `self` as a single string for HTTP POST
#
# Require: `curl.is_ok`
private fun to_url_encoded(curl: Curl): String
do
assert curl.is_ok
var lines = new Array[String]
for k, v in self do
if k.length == 0 then continue
k = curl.native.escape(k)
v = curl.native.escape(v)
lines.add "{k}={v}"
end
return lines.join("&")
end
# Concatenate couple of 'key value' separated by 'sep' in Array
fun join_pairs(sep: String): Array[String]
do
var col = new Array[String]
for k, v in self do col.add("{k}{sep}{v}")
return col
end
# Number of values in `self`
fun length: Int do return array.length
# Is this map empty?
fun is_empty: Bool do return array.is_empty
end
lib/curl/curl.nit:601,1--656,3