From e35d340b4667c08459b255f20cc6c0a47808af97 Mon Sep 17 00:00:00 2001 From: halx99 Date: Tue, 22 Jun 2021 14:19:22 +0800 Subject: [PATCH] Improve Uri parse --- cocos/network/Uri.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/cocos/network/Uri.cpp b/cocos/network/Uri.cpp index 2a350e201409..386762f5c828 100644 --- a/cocos/network/Uri.cpp +++ b/cocos/network/Uri.cpp @@ -2,6 +2,7 @@ * Copyright 2017 Facebook, Inc. * Copyright (c) 2017 Chukong Technologies * Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + * Copyright (c) 2021 Bytedance Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -198,16 +199,6 @@ bool Uri::doParse(const std::string& str) return false; } - if (hasScheme) - { - _scheme = submatch(match, 1); - toLower(_scheme); - if (_scheme == "https" || _scheme == "wss") - { - _isSecure = true; - } - } - std::string authorityAndPath(match[2].first, match[2].second); std::smatch authorityAndPathMatch; if (!std::regex_match(authorityAndPath.cbegin(), @@ -297,6 +288,25 @@ bool Uri::doParse(const std::string& str) _hostName = _host; } + if (hasScheme) { + _scheme = submatch(match, 1); + toLower(_scheme); + if (_scheme == "https" || _scheme == "wss") { + _isSecure = true; + if (_port == 0) + _port = 443; + } else if (_scheme == "http" || _scheme == "ws") { + if (_port == 0) + _port = 80; + } else if (_scheme == "ftp") { + if (_port == 0) + _port = 21; + } + } + + if (_path.empty()) + _path.push_back('/'); + return true; }