1 /* 2 * Copyright (c) 2020, The OpenThread Authors. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 3. Neither the name of the copyright holder nor the 13 * names of its contributors may be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** 30 * @file 31 * This file includes request definition for RESTful HTTP server. 32 */ 33 34 #ifndef OTBR_REST_REQUEST_HPP_ 35 #define OTBR_REST_REQUEST_HPP_ 36 37 #include <string> 38 #include <vector> 39 40 #include "common/code_utils.hpp" 41 #include "rest/types.hpp" 42 43 namespace otbr { 44 namespace rest { 45 46 /** 47 * This class implements an instance to host services used by border router. 48 * 49 */ 50 class Request 51 { 52 public: 53 /** 54 * The constructor is to initialize Request instance. 55 * 56 */ 57 Request(void); 58 59 /** 60 * This method sets the Url field of a request. 61 * 62 * @param[in] aString A pointer points to url string. 63 * @param[in] aLength Length of the url string 64 * 65 */ 66 void SetUrl(const char *aString, size_t aLength); 67 68 /** 69 * This method sets the body field of a request. 70 * 71 * @param[in] aString A pointer points to body string. 72 * @param[in] aLength Length of the body string 73 * 74 */ 75 void SetBody(const char *aString, size_t aLength); 76 77 /** 78 * This method sets the content-length field of a request. 79 * 80 * @param[in] aContentLength An unsigned integer representing content-length. 81 * 82 */ 83 void SetContentLength(size_t aContentLength); 84 85 /** 86 * This method sets the method of the parsed request. 87 * 88 * @param[in] aMethod An integer representing request method. 89 * 90 */ 91 void SetMethod(int32_t aMethod); 92 93 /** 94 * This method labels the request as complete which means it no longer need to be parsed one more time . 95 * 96 */ 97 void SetReadComplete(void); 98 99 /** 100 * This method resets the request then it could be set by parser from start. 101 * 102 */ 103 void ResetReadComplete(void); 104 105 /** 106 * This method returns the HTTP method of this request. 107 * 108 * @returns A integer representing HTTP method. 109 */ 110 HttpMethod GetMethod() const; 111 112 /** 113 * This method returns the HTTP method of this request. 114 * 115 * @returns A HttpMethod enum representing HTTP method of this request. 116 */ 117 std::string GetBody() const; 118 119 /** 120 * This method returns the url for this request. 121 * 122 * @returns A string contains the url of this request. 123 */ 124 std::string GetUrl(void) const; 125 126 /** 127 * This method indicates whether this request is parsed completely. 128 * 129 * 130 */ 131 bool IsComplete(void) const; 132 133 private: 134 int32_t mMethod; 135 size_t mContentLength; 136 std::string mUrl; 137 std::string mBody; 138 bool mComplete; 139 }; 140 141 } // namespace rest 142 } // namespace otbr 143 144 #endif // OTBR_REST_REQUEST_HPP_ 145