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 SEC_WEBSOCKET_ACCEPT = "Sec-WebSocket-Accept: "; 28 static constexpr std::string_view SEC_WEBSOCKET_KEY = "Sec-WebSocket-Key: "; 29 30 static std::string DecodeHeader(const std::string& headersText, std::string_view headerName); 31 }; 32 33 34 struct HttpRequest : private HttpBase { 35 std::string version; 36 std::string connection; 37 std::string upgrade; 38 std::string secWebSocketKey; 39 40 static bool Decode(const std::string& request, HttpRequest& parsed); 41 42 private: 43 static std::string DecodeVersion(const std::string& request, std::string::size_type methodStartPos); 44 }; 45 46 47 struct HttpResponse : private HttpBase { 48 std::string version; 49 std::string status; 50 std::string connection; 51 std::string upgrade; 52 std::string secWebSocketAccept; 53 54 static bool Decode(const std::string& response, HttpResponse& parsed); 55 56 private: 57 static std::string DecodeVersion(const std::string& response, std::string::size_type versionStartPos); 58 static std::string DecodeStatus(const std::string& response, std::string::size_type versionEndPos); 59 }; 60 } // namespace OHOS::ArkCompiler::Toolchain 61 62 #endif // ARKCOMPILER_TOOLCHAIN_WEBSOCKET_HTTP_H 63