All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.dataspray.runner.dto.web.HttpRequest Maven / Gradle / Ivy

There is a newer version: 0.0.14
Show newest version
/*
 * Copyright 2024 Matus Faro
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package io.dataspray.runner.dto.web;

import java.util.Base64;
import java.util.List;
import java.util.Map;

import static com.google.common.base.Preconditions.checkState;

/**
 * An HTTP request event sent to your Lambda function.
 *
 * @see AWS docs
 */
public interface HttpRequest {

    /**
     * The payload format version for this event. Lambda function URLs currently support payload format version 2.0.
     *
     * @see Version
     * history
     */
    String getVersion();

    /**
     * The request path. For example, if the request URL is
     * 
https://{url-id}.lambda-url.{region}.on.aws/example/test/demo
, then the raw path value is *
/example/test/demo
. */ String getRawPath(); /** * The raw string containing the request's query string parameters. Supported characters include a-z, A-Z, 0-9, ., * _, -, %, &, =, and +. */ String getRawQueryString(); /** * An array containing all cookies sent as part of the request. */ List getCookies(); /** * A map containing all cookies and their values, backed by a Map with case-insensitive keys. */ Map getCookiesCaseInsensitive(); /** * The list of request headers. */ Map getHeaders(); /** * The list of request headers, backed by a Map with case-insensitive keys. */ Map getHeadersCaseInsensitive(); /** * The query parameters for the request. For example, if the request URL is *
https://{url-id}.lambda-url.{region}.on.aws/example?name=Jane
, then the queryStringParameters value is * a JSON object with a key of name and a value of Jane. */ Map getQueryStringParameters(); /** * An object that contains additional information about the request, such as the requestId, the time of the request, * and the identity of the caller if authorized via AWS Identity and Access Management (IAM). */ HttpRequestContext getHttpRequestContext(); /** * The body of the request. If the content type of the request is binary, the body is base64-encoded. */ String getBody(); /** * The body of the request as a String, throwing an exception if the body is binary and base64-encoded. * * @throws IllegalStateException if the body is base64-encoded */ default String getBodyAsString() throws IllegalStateException { checkState(!isBase64Encoded(), "Body is binary, call getBodyAsBinary() instead"); return getBody(); } /** * The body of the request as a binary array, converting from Base64 if necessary. */ default byte[] getBodyAsBinary() { if (isBase64Encoded()) { return Base64.getDecoder().decode(getBody()); } else { return getBody().getBytes(); } } /** * TRUE if the body is a binary payload and base64-encoded. FALSE otherwise. */ boolean isBase64Encoded(); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy