2 * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.restconf.server.api;
10 import static java.util.Objects.requireNonNull;
12 import org.eclipse.jdt.annotation.NonNullByDefault;
13 import org.opendaylight.restconf.api.QueryParameters;
14 import org.opendaylight.restconf.api.query.PrettyPrintParam;
17 * A request to {@link RestconfServer}. It contains state and binding established by whoever is performing binding to
18 * HTTP transport layer. This includes:
20 * <li>HTTP request {@link #queryParameters() query parameters},</li>
21 * <li>{@link #prettyPrint() pretty printing}, including affected by query parameters<li>
23 * It notably does <b>not</b> hold the HTTP request path, nor the request body. Those are passed as separate arguments
24 * to server methods as implementations of those methods are expected to act on them.
27 public record ServerRequest(QueryParameters queryParameters, PrettyPrintParam prettyPrint) {
28 // TODO: this is where a binding to security principal and access control should be:
29 // - we would like to be able to have java.security.Principal#name() for logging purposes
30 // - we need to have a NACM-capable interface, through which we can check permissions (such as data PUT) and
31 // establish output filters (i.e. excluding paths inaccessible path to user from a data GET a ContainerNode)
32 public ServerRequest {
33 requireNonNull(queryParameters);
34 requireNonNull(prettyPrint);
37 public static ServerRequest of(final QueryParameters queryParameters, final PrettyPrintParam defaultPrettyPrint) {
38 final var prettyPrint = queryParameters.lookup(PrettyPrintParam.uriName, PrettyPrintParam::forUriValue);
39 return prettyPrint == null ? new ServerRequest(queryParameters, defaultPrettyPrint)
40 : new ServerRequest(queryParameters.withoutParam(PrettyPrintParam.uriName), prettyPrint);