C++ Rest SDK
The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
http_helpers.h
1 /***
2 * ==++==
3 *
4 * Copyright (c) Microsoft Corporation. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * ==--==
17 * =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
18 *
19 * Implementation Details of the http.h layer of messaging
20 *
21 * Functions and types for interoperating with http.h from modern C++
22 * This file includes windows definitions and should not be included in a public header
23 *
24 * For the latest on this and related APIs, please see http://casablanca.codeplex.com.
25 *
26 * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
27 ****/
28 #pragma once
29 
30 #include "cpprest/http_msg.h"
31 
32 namespace web { namespace http
33 {
34 namespace details
35 {
36 
40  class mime_types
41  {
42  public:
43  #define _MIME_TYPES
44  #define DAT(a,b) _ASYNCRTIMP const static utility::string_t a;
45  #include "cpprest/details/http_constants.dat"
46  #undef _MIME_TYPES
47  #undef DAT
48  };
49 
54  {
55  public:
56  #define _CHARSET_TYPES
57  #define DAT(a,b) _ASYNCRTIMP const static utility::string_t a;
58  #include "cpprest/details/http_constants.dat"
59  #undef _CHARSET_TYPES
60  #undef DAT
61  };
62 
66  bool is_content_type_textual(const utility::string_t &content_type);
67 
71  bool is_content_type_json(const utility::string_t &content_type);
72 
77  void parse_content_type_and_charset(const utility::string_t &content_type, utility::string_t &content, utility::string_t &charset);
78 
82  utility::string_t get_default_charset(const utility::string_t &content_type);
83 
87  utility::string_t get_default_reason_phrase(status_code code);
88 
93  utility::string_t convert_utf16_to_string_t(utf16string src);
94  utf16string convert_utf16_to_utf16(utf16string src);
95  std::string convert_utf16_to_utf8(utf16string src);
96  utility::string_t convert_utf16le_to_string_t(utf16string src, bool erase_bom);
97  std::string convert_utf16le_to_utf8(utf16string src, bool erase_bom);
98  utility::string_t convert_utf16be_to_string_t(utf16string src, bool erase_bom);
99  std::string convert_utf16be_to_utf8(utf16string src, bool erase_bom);
100  utf16string convert_utf16be_to_utf16le(utf16string src, bool erase_bom);
101 
102  // simple helper functions to trim whitespace.
103  _ASYNCRTIMP void __cdecl ltrim_whitespace(utility::string_t &str);
104  _ASYNCRTIMP void __cdecl rtrim_whitespace(utility::string_t &str);
105  _ASYNCRTIMP void __cdecl trim_whitespace(utility::string_t &str);
106 
107  bool validate_method(const utility::string_t& method);
108 
109 
110  namespace chunked_encoding
111  {
112  // Transfer-Encoding: chunked support
113  static const size_t additional_encoding_space = 12;
114  static const size_t data_offset = additional_encoding_space-2;
115 
116  // Add the data necessary for properly sending data with transfer-encoding: chunked.
117  //
118  // There are up to 12 additional bytes needed for each chunk:
119  //
120  // The last chunk requires 5 bytes, and is fixed.
121  // All other chunks require up to 8 bytes for the length, and four for the two CRLF
122  // delimiters.
123  //
124  _ASYNCRTIMP size_t __cdecl add_chunked_delimiters(_Out_writes_(buffer_size) uint8_t *data, _In_ size_t buffer_size, size_t bytes_read);
125  }
126 
127 }}}
Constants for charset types.
Definition: http_helpers.h:53
The web namespace contains functionality common to multiple protocols like HTTP and WebSockets...
Definition: base_uri.h:37
utility::string_t method
Predefined method strings for the standard HTTP methods mentioned in the HTTP 1.1 specification...
Definition: http_msg.h:62
Constants for MIME types.
Definition: http_helpers.h:40