@marcel91200 / caddy Mirror · read-only
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 11, 01:00 UTC

master
go 57 lines 1.79 KB
Raw
1 // Copyright 2015 Matthew Holt and The Caddy Authors
2 //
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 // Most of the code in this file was initially borrowed from the Go
16 // standard library and modified; It had this copyright notice:
17 // Copyright 2021 The Go Authors. All rights reserved.
18 // Use of this source code is governed by a BSD-style
19 // license that can be found in the LICENSE file.
20
21 // Original source, copied because the package was marked internal:
22 // https://github.com/golang/go/blob/5c489514bc5e61ad9b5b07bd7d8ec65d66a0512a/src/net/http/internal/ascii/print.go
23
24 package reverseproxy
25
26 // asciiEqualFold is strings.EqualFold, ASCII only. It reports whether s and t
27 // are equal, ASCII-case-insensitively.
28 func asciiEqualFold(s, t string) bool {
29 if len(s) != len(t) {
30 return false
31 }
32 for i := 0; i < len(s); i++ {
33 if asciiLower(s[i]) != asciiLower(t[i]) {
34 return false
35 }
36 }
37 return true
38 }
39
40 // asciiLower returns the ASCII lowercase version of b.
41 func asciiLower(b byte) byte {
42 if 'A' <= b && b <= 'Z' {
43 return b + ('a' - 'A')
44 }
45 return b
46 }
47
48 // asciiIsPrint returns whether s is ASCII and printable according to
49 // https://tools.ietf.org/html/rfc20#section-4.2.
50 func asciiIsPrint(s string) bool {
51 for i := 0; i < len(s); i++ {
52 if s[i] < ' ' || s[i] > '~' {
53 return false
54 }
55 }
56 return true
57 }