-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
client/web: add support for zst precomppressed assets
This will enable us to reduce the size of these embedded assets. Updates tailscale/corp#20099 Signed-off-by: James Tucker <james@tailscale.com>
- Loading branch information
Showing
10 changed files
with
171 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) Tailscale Inc & AUTHORS | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
// Package tswebutil contains helper code used in various Tailscale webservers, without the tsweb kitchen sink. | ||
package tswebutil | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
|
||
"go4.org/mem" | ||
) | ||
|
||
// AcceptsEncoding reports whether r accepts the named encoding | ||
// ("gzip", "br", etc). | ||
func AcceptsEncoding(r *http.Request, enc string) bool { | ||
h := r.Header.Get("Accept-Encoding") | ||
if h == "" { | ||
return false | ||
} | ||
if !strings.Contains(h, enc) && !mem.ContainsFold(mem.S(h), mem.S(enc)) { | ||
return false | ||
} | ||
remain := h | ||
for len(remain) > 0 { | ||
var part string | ||
part, remain, _ = strings.Cut(remain, ",") | ||
part = strings.TrimSpace(part) | ||
part, _, _ = strings.Cut(part, ";") | ||
if part == enc { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) Tailscale Inc & AUTHORS | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
package tswebutil | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestAcceptsEncoding(t *testing.T) { | ||
tests := []struct { | ||
in, enc string | ||
want bool | ||
}{ | ||
{"", "gzip", false}, | ||
{"gzip", "gzip", true}, | ||
{"foo,gzip", "gzip", true}, | ||
{"foo, gzip", "gzip", true}, | ||
{"foo, gzip ", "gzip", true}, | ||
{"gzip, foo ", "gzip", true}, | ||
{"gzip, foo ", "br", false}, | ||
{"gzip, foo ", "fo", false}, | ||
{"gzip;q=1.2, foo ", "gzip", true}, | ||
{" gzip;q=1.2, foo ", "gzip", true}, | ||
} | ||
for i, tt := range tests { | ||
h := make(http.Header) | ||
if tt.in != "" { | ||
h.Set("Accept-Encoding", tt.in) | ||
} | ||
got := AcceptsEncoding(&http.Request{Header: h}, tt.enc) | ||
if got != tt.want { | ||
t.Errorf("%d. got %v; want %v", i, got, tt.want) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters