Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
run: sudo apt-get remove llvm-18
- name: Checkout
uses: actions/checkout@v6
- name: Pull musl, bdwgc
- name: Pull musl, bdwgc, and net
run: |
git submodule update --init lib/musl lib/bdwgc
git submodule update --init lib/musl lib/bdwgc src/net
- name: Restore LLVM source cache
uses: actions/cache/restore@v5
id: cache-llvm-source
Expand Down
7 changes: 6 additions & 1 deletion loader/goroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,12 @@ func pathsToOverride(goMinor int, needsSyscallPackage bool) map[string]bool {
"internal/wasi/": false,
"machine/": false,
"net/": true,
"net/http/": false,
"net/http/": true,
"net/http/httptest/": false,
"net/http/httptrace/": false,
"net/http/httputil/": false,
"net/http/internal/": false,
"net/http/pprof/": false,
"os/": true,
"reflect/": false,
"runtime/": false,
Expand Down
51 changes: 51 additions & 0 deletions loader/goroot_cookiejar_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package loader

import (
"os"
"path/filepath"
"testing"
)

func TestHTTPSubpackageMerge(t *testing.T) {
goRoot := t.TempDir()
tinyRoot := t.TempDir()
files := map[string][]string{
goRoot: {"client.go", "cookiejar/jar.go", "httptest/server.go", "internal/ascii/print.go"},
tinyRoot: {"client.go", "httptest/server.go", "internal/ascii/print.go"},
}
for root, names := range files {
for _, name := range names {
file := filepath.Join(root, "src/net/http", name)
if err := os.MkdirAll(filepath.Dir(file), 0755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(file, []byte("package http\n"), 0644); err != nil {
t.Fatal(err)
}
}
}
paths := pathsToOverride(26, false)
overrides := make(map[string]bool)
for _, path := range []string{"net/http/", "net/http/httptest/", "net/http/internal/"} {
value, ok := paths[path]
if !ok {
t.Fatalf("missing override for %s", path)
}
overrides[path] = value
}
links, err := listGorootMergeLinks(goRoot, tinyRoot, overrides)
if err != nil {
t.Fatal(err)
}
for path, root := range map[string]string{
"net/http/client.go": tinyRoot,
"net/http/cookiejar": goRoot,
"net/http/httptest": tinyRoot,
"net/http/internal": tinyRoot,
} {
key := filepath.Join("src", path)
if want := filepath.Join(root, key); links[key] != want {
t.Errorf("%s links to %q, want %q", path, links[key], want)
}
}
}
1 change: 1 addition & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func TestBuild(t *testing.T) {
t.Parallel()
hostOptions := optionsFromTarget("", sema)
runPlatTests(hostOptions, tests, t)
runPlatTests(hostOptions, []string{"cookiejar.go"}, t)

// scheduler.threads needs threadID, which exists only on Linux and Darwin.
// scheduler.none does not link on Windows.
Expand Down
27 changes: 27 additions & 0 deletions testdata/cookiejar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"net/http"
"net/http/cookiejar"
"net/url"
)

func main() {
jar, err := cookiejar.New(nil)
if err != nil {
panic(err)
}
u, err := url.Parse("https://example.com/account")
if err != nil {
panic(err)
}
jar.SetCookies(u, []*http.Cookie{{Name: "session", Value: "value", Secure: true, Path: "/"}})
if cookies := jar.Cookies(u); len(cookies) != 1 || cookies[0].Value != "value" {
panic("cookie not stored")
}
u.Scheme = "http"
if len(jar.Cookies(u)) != 0 {
panic("secure cookie sent over HTTP")
}
println("cookie stored; secure cookie refused over HTTP")
}
1 change: 1 addition & 0 deletions testdata/cookiejar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cookie stored; secure cookie refused over HTTP