github.com/aacfactory/fns@v1.2.85/transports/middlewares/cors/header.go (about) 1 /* 2 * Copyright 2023 Wang Min Xiang 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18 package cors 19 20 import "bytes" 21 22 var ( 23 comma = []byte{','} 24 ) 25 26 func parseHeaderList(headerList [][]byte) ([][]byte, bool) { 27 out := headerList 28 copied := false 29 for i, v := range headerList { 30 needsSplit := bytes.IndexByte(v, ',') != -1 31 if !copied { 32 if needsSplit { 33 split := bytes.Split(v, comma) 34 out = make([][]byte, i, len(headerList)+len(split)-1) 35 copy(out, headerList[:i]) 36 for _, s := range split { 37 out = append(out, bytes.TrimSpace(s)) 38 } 39 copied = true 40 } 41 } else { 42 if needsSplit { 43 split := bytes.Split(v, comma) 44 for _, s := range split { 45 out = append(out, bytes.TrimSpace(s)) 46 } 47 } else { 48 out = append(out, v) 49 } 50 } 51 } 52 return out, copied 53 }