MySQL 8.0.39
Source Code Documentation
content_type.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2019, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQLROUTER_HTTP_CONTENT_TYPE_INCLUDED
27#define MYSQLROUTER_HTTP_CONTENT_TYPE_INCLUDED
28
30
31#include <algorithm>
32#include <array>
33#include <string>
34
36 public:
37 // RFC4329 deprecated text/javascript for application/javascript
38 static constexpr const char ApplicationJavascript[] =
39 "application/javascript";
40 static constexpr const char ApplicationJson[] = "application/json";
41 static constexpr const char ApplicationOctetStream[] =
42 "application/octet-stream";
43 static constexpr const char TextCss[] = "text/css";
44 static constexpr const char TextHtml[] = "text/html";
45 static constexpr const char ImageJpeg[] = "image/jpeg";
46 static constexpr const char ImagePng[] = "image/png";
47 static constexpr const char ImageSvgXML[] = "image/svg+xml";
48};
49
51 public:
52 /**
53 * get a mimetype for a file-extension.
54 *
55 * file-extension is matched case-insensitive
56 *
57 * returns 'application/octet-stream' in case no mapping is found
58 *
59 * @returns a mimetype for the extension
60 * @retval 'application/octet-stream' if no mapping is found
61 */
62 static const char *from_extension(std::string extension) {
63 // sorted list of extensions and their mapping to their mimetype
64 const std::array<std::pair<std::string, const char *>, 9> mimetypes{{
65 std::make_pair("css", MimeType::TextCss),
66 std::make_pair("htm", MimeType::TextHtml),
67 std::make_pair("html", MimeType::TextHtml),
68 std::make_pair("jpeg", MimeType::ImageJpeg),
69 std::make_pair("jpg", MimeType::ImageJpeg),
70 std::make_pair("js", MimeType::ApplicationJavascript),
71 std::make_pair("json", MimeType::ApplicationJson),
72 std::make_pair("png", MimeType::ImagePng),
73 std::make_pair("svg", MimeType::ImageSvgXML),
74 }};
75
76 // lower-case file-extensions.
77 //
78 // Use ASCII only conversion as our map is ASCII too
79 //
80 // not using std::lolower() and friends as they are locale-aware which
81 // isn't wanted in this case.
83 extension.begin(), extension.end(), extension.begin(),
84 [](char c) { return (c >= 'A' && c <= 'Z') ? c + ('z' - 'Z') : c; });
85
86 auto low_bound_it = std::lower_bound(
87 mimetypes.begin(), mimetypes.end(), extension,
88 [](const auto &a, const auto &_ext) { return a.first < _ext; });
89
90 // std::lower_bound() returns it to first element that's >= value
91 return (low_bound_it != mimetypes.end() && low_bound_it->first == extension)
92 ? low_bound_it->second
94 }
95};
96
97#endif
Definition: content_type.h:50
static const char * from_extension(std::string extension)
get a mimetype for a file-extension.
Definition: content_type.h:62
Definition: content_type.h:35
static constexpr const char ImageSvgXML[]
Definition: content_type.h:47
static constexpr const char ImageJpeg[]
Definition: content_type.h:45
static constexpr const char TextCss[]
Definition: content_type.h:43
static constexpr const char ImagePng[]
Definition: content_type.h:46
static constexpr const char ApplicationOctetStream[]
Definition: content_type.h:41
static constexpr const char TextHtml[]
Definition: content_type.h:44
static constexpr const char ApplicationJson[]
Definition: content_type.h:40
static constexpr const char ApplicationJavascript[]
Definition: content_type.h:38
#define HTTP_SERVER_EXPORT
Definition: http_server_export.h:40
bool transform(const dd::Spatial_reference_system *source_srs, const Geometry &in, const dd::Spatial_reference_system *target_srs, const char *func_name, std::unique_ptr< Geometry > *out) noexcept
Transforms a geometry from one SRS to another.
Definition: transform.cc:216