Search in sources :

Example 6 with Parameters

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));
}
Also used : Parameters(io.helidon.common.http.Parameters) Test(org.junit.jupiter.api.Test)

Example 7 with Parameters

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));
}
Also used : Parameters(io.helidon.common.http.Parameters) Test(org.junit.jupiter.api.Test)

Example 8 with Parameters

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"));
}
Also used : Parameters(io.helidon.common.http.Parameters) Test(org.junit.jupiter.api.Test)

Example 9 with Parameters

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()));
}
Also used : Parameters(io.helidon.common.http.Parameters) Test(org.junit.jupiter.api.Test)

Example 10 with Parameters

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;
}
Also used : Parameters(io.helidon.common.http.Parameters) HashParameters(io.helidon.common.http.HashParameters)

Aggregations

Parameters (io.helidon.common.http.Parameters)16 Test (org.junit.jupiter.api.Test)11 HashParameters (io.helidon.common.http.HashParameters)3 HaInfo (com.sun.xml.ws.api.ha.HaInfo)1 DataChunk (io.helidon.common.http.DataChunk)1 Http (io.helidon.common.http.Http)1 MediaType (io.helidon.common.http.MediaType)1 ReadOnlyParameters (io.helidon.common.http.ReadOnlyParameters)1 MediaContext (io.helidon.media.common.MediaContext)1 MessageBodyReader (io.helidon.media.common.MessageBodyReader)1 JsonpSupport (io.helidon.media.jsonp.JsonpSupport)1 SecurityContext (io.helidon.security.SecurityContext)1 SecurityEnvironment (io.helidon.security.SecurityEnvironment)1 Handler (io.helidon.webserver.Handler)1 HttpException (io.helidon.webserver.HttpException)1 RequestPredicate (io.helidon.webserver.RequestPredicate)1 Routing (io.helidon.webserver.Routing)1 ServerRequest (io.helidon.webserver.ServerRequest)1 WebServer (io.helidon.webserver.WebServer)1 JerseySupport (io.helidon.webserver.jersey.JerseySupport)1