iceberg-cpp
Loading...
Searching...
No Matches
http_request.h
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
22#include <algorithm>
23#include <cctype>
24#include <cstddef>
25#include <cstdint>
26#include <map>
27#include <string>
28#include <string_view>
29
30#include "iceberg/catalog/rest/iceberg_rest_export.h"
31
32namespace iceberg::rest {
33
35enum class HttpMethod : uint8_t { kGet, kPost, kPut, kDelete, kHead };
36
38constexpr std::string_view ToString(HttpMethod method) {
39 switch (method) {
40 case HttpMethod::kGet:
41 return "GET";
42 case HttpMethod::kPost:
43 return "POST";
44 case HttpMethod::kPut:
45 return "PUT";
46 case HttpMethod::kDelete:
47 return "DELETE";
48 case HttpMethod::kHead:
49 return "HEAD";
50 }
51 return "UNKNOWN";
52}
53
59 using is_transparent = void;
60
61 bool operator()(std::string_view lhs, std::string_view rhs) const noexcept {
62 const auto min_size = lhs.size() < rhs.size() ? lhs.size() : rhs.size();
63 for (std::size_t i = 0; i < min_size; ++i) {
64 auto left = static_cast<unsigned char>(lhs[i]);
65 auto right = static_cast<unsigned char>(rhs[i]);
66 const int lower_left = std::tolower(left);
67 const int lower_right = std::tolower(right);
68 if (lower_left < lower_right) return true;
69 if (lower_left > lower_right) return false;
70 }
71 return lhs.size() < rhs.size();
72 }
73};
74
82using HttpHeaders = std::map<std::string, std::string, CaseInsensitiveHeaderLess>;
83
86struct ICEBERG_REST_EXPORT HttpRequest {
87 HttpMethod method = HttpMethod::kGet;
88 std::string url;
89 HttpHeaders headers;
90 std::string body;
91};
92
93} // namespace iceberg::rest
Case-insensitive ordering for HTTP header names.
Definition http_request.h:58
An outgoing HTTP request. Mirrors Java's HttpRequest so signing implementations like SigV4 see method...
Definition http_request.h:86