1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ARKCOMPILER_TOOLCHAIN_WEBSOCKET_HTTP_H 17 #define ARKCOMPILER_TOOLCHAIN_WEBSOCKET_HTTP_H 18 19 #include <string> 20 21 namespace OHOS::ArkCompiler::Toolchain { 22 struct HttpBase { 23 static constexpr std::string_view EOL = "\r\n"; 24 static constexpr std::string_view GET = "GET"; 25 static constexpr std::string_view CONNECTION = "Connection: "; 26 static constexpr std::string_view UPGRADE = "Upgrade: "; 27 static constexpr std::string_view ORIGIN = "Origin: "; 28 static constexpr std::string_view SEC_WEBSOCKET_ACCEPT = "Sec-WebSocket-Accept: "; 29 static constexpr std::string_view SEC_WEBSOCKET_KEY = "Sec-WebSocket-Key: "; 30 31 static std::string DecodeHeader(const std::string& headersText, std::string_view headerName); 32 }; 33 34 35 struct HttpRequest : private HttpBase { 36 std::string version; 37 std::string connection; 38 std::string upgrade; 39 std::string secWebSocketKey; 40 41 static bool Decode(const std::string& request, HttpRequest& parsed); 42 43 private: 44 static std::string DecodeVersion(const std::string& request, std::string::size_type methodStartPos); 45 }; 46 47 48 struct HttpResponse : private HttpBase { 49 std::string version; 50 std::string status; 51 std::string connection; 52 std::string upgrade; 53 std::string secWebSocketAccept; 54 55 static bool Decode(const std::string& response, HttpResponse& parsed); 56 57 private: 58 static std::string DecodeVersion(const std::string& response, std::string::size_type versionStartPos); 59 static std::string DecodeStatus(const std::string& response, std::string::size_type versionEndPos); 60 }; 61 } // namespace OHOS::ArkCompiler::Toolchain 62 63 #endif // ARKCOMPILER_TOOLCHAIN_WEBSOCKET_HTTP_H 64