github.com/cloudwego/hertz@v0.9.3/pkg/protocol/uri_windows.go (about) 1 //go:build windows 2 // +build windows 3 4 /* 5 * Copyright 2022 CloudWeGo Authors 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * 19 * The MIT License (MIT) 20 * 21 * Copyright (c) 2015-present Aliaksandr Valialkin, VertaMedia, Kirill Danshin, Erik Dubbelboer, FastHTTP Authors 22 * 23 * Permission is hereby granted, free of charge, to any person obtaining a copy 24 * of this software and associated documentation files (the "Software"), to deal 25 * in the Software without restriction, including without limitation the rights 26 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 * copies of the Software, and to permit persons to whom the Software is 28 * furnished to do so, subject to the following conditions: 29 * 30 * The above copyright notice and this permission notice shall be included in 31 * all copies or substantial portions of the Software. 32 * 33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 39 * THE SOFTWARE. 40 * 41 * This file may have been modified by CloudWeGo authors. All CloudWeGo 42 * Modifications are Copyright 2022 CloudWeGo Authors. 43 */ 44 45 package protocol 46 47 import "github.com/cloudwego/hertz/pkg/common/hlog" 48 49 func addLeadingSlash(dst, src []byte) []byte { 50 // zero length and "C:/" case 51 isDisk := len(src) > 2 && src[1] == ':' 52 if len(src) == 0 || (!isDisk && src[0] != '/') { 53 dst = append(dst, '/') 54 } 55 56 return dst 57 } 58 59 // checkSchemeWhenCharIsColon check url begin with : 60 // Scenarios that handle protocols like "http:" 61 // Add the path to the win file, e.g. "E:\gopath", "E:\". 62 func checkSchemeWhenCharIsColon(i int, rawURL []byte) (scheme, path []byte) { 63 if i == 0 { 64 hlog.Errorf("error happened when trying to parse the rawURL(%s): missing protocol scheme", rawURL) 65 return 66 } 67 68 // case :\ 69 if i+1 < len(rawURL) && rawURL[i+1] == '\\' { 70 return nil, rawURL 71 } 72 73 return rawURL[:i], rawURL[i+1:] 74 }