iceberg-cpp
Loading...
Searching...
No Matches
http_request.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
24
25#include <algorithm>
26#include <cctype>
27#include <cstddef>
28#include <cstdint>
29#include <map>
30#include <string>
31#include <string_view>
32
34
35namespace iceberg::rest {
36
38enum class HttpMethod : uint8_t { kGet, kPost, kPut, kDelete, kHead };
39
41constexpr std::string_view ToString(HttpMethod method) {
42 switch (method) {
43 case HttpMethod::kGet:
44 return "GET";
45 case HttpMethod::kPost:
46 return "POST";
47 case HttpMethod::kPut:
48 return "PUT";
49 case HttpMethod::kDelete:
50 return "DELETE";
51 case HttpMethod::kHead:
52 return "HEAD";
53 }
54 return "UNKNOWN";
55}
56
62 using is_transparent = void;
63
64 bool operator()(std::string_view lhs, std::string_view rhs) const noexcept {
65 const auto min_size = lhs.size() < rhs.size() ? lhs.size() : rhs.size();
66 for (std::size_t i = 0; i < min_size; ++i) {
67 auto left = static_cast<unsigned char>(lhs[i]);
68 auto right = static_cast<unsigned char>(rhs[i]);
69 const int lower_left = std::tolower(left);
70 const int lower_right = std::tolower(right);
71 if (lower_left < lower_right) return true;
72 if (lower_left > lower_right) return false;
73 }
74 return lhs.size() < rhs.size();
75 }
76};
77
85using HttpHeaders = std::map<std::string, std::string, CaseInsensitiveHeaderLess>;
86
89struct ICEBERG_REST_EXPORT HttpRequest {
90 HttpMethod method = HttpMethod::kGet;
91 std::string url;
92 HttpHeaders headers;
93 std::string body;
94};
95
96} // namespace iceberg::rest
Define symbol visibility macros for the REST catalog library.
REST catalog APIs.
Definition auth_manager.h:34
std::map< std::string, std::string, CaseInsensitiveHeaderLess > HttpHeaders
Single-value HTTP headers with case-insensitive names.
Definition http_request.h:85
constexpr std::string_view ToString(HttpMethod method)
Convert HttpMethod to string representation.
Definition http_request.h:41
HttpMethod
HTTP method enumeration.
Definition http_request.h:38
Case-insensitive ordering for HTTP header names.
Definition http_request.h:61
An outgoing HTTP request. Mirrors Java's HttpRequest so signing implementations like SigV4 see method...
Definition http_request.h:89