use of io.helidon.common.http.Parameters in project helidon by oracle.
the class UriComponentTest method sanityParse.
@SuppressWarnings("unchecked")
@Test
public void sanityParse() throws Exception {
Parameters parameters = UriComponent.decodeQuery(URI.create("http://foo/bar?a=b&c=d&a=e").getRawQuery(), true);
assertThat(parameters.all("a"), hasItems(is("b"), is("e")));
assertThat(parameters.all("c"), hasItems(is("d")));
assertThat(parameters.all("z"), hasSize(0));
}
use of io.helidon.common.http.Parameters in project helidon by oracle.
the class CookieParserTest method emptyAndNull.
@Test
public void emptyAndNull() throws Exception {
Parameters p = HashRequestHeaders.CookieParser.parse(null);
assertThat(p, notNullValue());
assertThat(p.toMap().isEmpty(), is(true));
p = HashRequestHeaders.CookieParser.parse("");
assertThat(p, notNullValue());
assertThat(p.toMap().isEmpty(), is(true));
}
use of io.helidon.common.http.Parameters in project helidon by oracle.
the class UriComponentTest method yesDecode.
@Test
public void yesDecode() throws Exception {
Parameters parameters = UriComponent.decodeQuery("a=" + URLEncoder.encode("1&b=2", US_ASCII.name()), true);
assertThat(parameters.first("a").get(), is("1&b=2"));
}
use of io.helidon.common.http.Parameters in project helidon by oracle.
the class UriComponentTest method testNonExistingParam.
@Test
public void testNonExistingParam() throws Exception {
Parameters parameters = UriComponent.decodeQuery("a=b", true);
assertThat(parameters.first("c"), is(Optional.empty()));
}
use of io.helidon.common.http.Parameters in project helidon by oracle.
the class UriComponent method decodeQuery.
/**
* Decode the query component of a URI.
* <p>
* Decoding of query parameter names and values can be controlled using the {@code decodeNames}
* and {@code decodeValues} parameter flags.
*
* @param query the query component in encoded form.
* @param decodeNames {@code true} if the returned query parameter names of the query component
* should be in decoded form.
* @param decodeValues {@code true} if the returned query parameter values of the query component
* should be in decoded form.
* @return the multivalued map of query parameters.
*/
static Parameters decodeQuery(String query, boolean decodeNames, boolean decodeValues) {
Parameters queryParameters = HashParameters.create();
if (query == null || query.isEmpty()) {
return queryParameters;
}
int s = 0;
do {
int e = query.indexOf('&', s);
if (e == -1) {
decodeQueryParam(queryParameters, query.substring(s), decodeNames, decodeValues);
} else if (e > s) {
decodeQueryParam(queryParameters, query.substring(s, e), decodeNames, decodeValues);
}
s = e + 1;
} while (s > 0 && s < query.length());
return queryParameters;
}
Aggregations