MySQL 8.3.0
Source Code Documentation
content_type.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2019, 2023, 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 also distributed 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 included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24
25#ifndef MYSQLROUTER_HTTP_CONTENT_TYPE_INCLUDED
26#define MYSQLROUTER_HTTP_CONTENT_TYPE_INCLUDED
27
29
30#include <algorithm>
31#include <array>
32#include <string>
33
35 public:
36 // RFC4329 deprecated text/javascript for application/javascript
37 static constexpr const char ApplicationJavascript[] =
38 "application/javascript";
39 static constexpr const char ApplicationJson[] = "application/json";
40 static constexpr const char ApplicationOctetStream[] =
41 "application/octet-stream";
42 static constexpr const char TextCss[] = "text/css";
43 static constexpr const char TextHtml[] = "text/html";
44 static constexpr const char ImageJpeg[] = "image/jpeg";
45 static constexpr const char ImagePng[] = "image/png";
46 static constexpr const char ImageSvgXML[] = "image/svg+xml";
47};
48
50 public:
51 /**
52 * get a mimetype for a file-extension.
53 *
54 * file-extension is matched case-insensitive
55 *
56 * returns 'application/octet-stream' in case no mapping is found
57 *
58 * @returns a mimetype for the extension
59 * @retval 'application/octet-stream' if no mapping is found
60 */
61 static const char *from_extension(std::string extension) {
62 // sorted list of extensions and their mapping to their mimetype
63 const std::array<std::pair<std::string, const char *>, 9> mimetypes{{
64 std::make_pair("css", MimeType::TextCss),
65 std::make_pair("htm", MimeType::TextHtml),
66 std::make_pair("html", MimeType::TextHtml),
67 std::make_pair("jpeg", MimeType::ImageJpeg),
68 std::make_pair("jpg", MimeType::ImageJpeg),
69 std::make_pair("js", MimeType::ApplicationJavascript),
70 std::make_pair("json", MimeType::ApplicationJson),
71 std::make_pair("png", MimeType::ImagePng),
72 std::make_pair("svg", MimeType::ImageSvgXML),
73 }};
74
75 // lower-case file-extensions.
76 //
77 // Use ASCII only conversion as our map is ASCII too
78 //
79 // not using std::lolower() and friends as they are locale-aware which
80 // isn't wanted in this case.
82 extension.begin(), extension.end(), extension.begin(),
83 [](char c) { return (c >= 'A' && c <= 'Z') ? c + ('z' - 'Z') : c; });
84
85 auto low_bound_it = std::lower_bound(
86 mimetypes.begin(), mimetypes.end(), extension,
87 [](const auto &a, const auto &_ext) { return a.first < _ext; });
88
89 // std::lower_bound() returns it to first element that's >= value
90 return (low_bound_it != mimetypes.end() && low_bound_it->first == extension)
91 ? low_bound_it->second
93 }
94};
95
96#endif
Definition: content_type.h:49
static const char * from_extension(std::string extension)
get a mimetype for a file-extension.
Definition: content_type.h:61
Definition: content_type.h:34
static constexpr const char ImageSvgXML[]
Definition: content_type.h:46
static constexpr const char ImageJpeg[]
Definition: content_type.h:44
static constexpr const char TextCss[]
Definition: content_type.h:42
static constexpr const char ImagePng[]
Definition: content_type.h:45
static constexpr const char ApplicationOctetStream[]
Definition: content_type.h:40
static constexpr const char TextHtml[]
Definition: content_type.h:43
static constexpr const char ApplicationJson[]
Definition: content_type.h:39
static constexpr const char ApplicationJavascript[]
Definition: content_type.h:37
#define HTTP_SERVER_EXPORT
Definition: http_server_export.h:39
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:215