Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: Server is sending 304 even if it is running in a different directory #42051

Closed
ghost opened this issue Oct 18, 2020 · 2 comments
Closed

Comments

@ghost
Copy link

ghost commented Oct 18, 2020

What version of Go are you using (go version)?

$ go version
go version go1.15.2 linux/amd64

Does this issue reproduce with the latest release?

No sure.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/cubte/.cache/go-build"
GOENV="/home/cubte/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/cubte/.local/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/cubte/.local/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build051727565=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I have this program,

package main

import (
	"flag"
	"fmt"
	"log"
	"net/http"
	"os"
	"strconv"
)

func main() {
	port := flag.Int("p", 8000, "port number")
	dir := flag.String("d", ".", "directory path")
	flag.Parse()

	fi, err := os.Stat(*dir)
	if err != nil {
		log.Fatal(err)
	}
	if !fi.IsDir() {
		log.Fatal(fmt.Errorf("%s isn't a directory\n", *dir))
	}

	addr := ":" + strconv.Itoa(*port)
	handler := http.FileServer(http.Dir(*dir))

	fmt.Printf("serving %s on http://localhost:%d\n", *dir, *port)
	log.Fatal(http.ListenAndServe(addr, handler))
}

I compiled and ran it on my home directory. I went to web browser and visited localhost:8000. I then stopped the program and ran it inside a directory of home directory. when i refresh the browser window i don't see that directory's content. I still see the previous directory. The server is still sending 304. It requires to disable cache to see the content of the directory where the server is currently running.

What did you expect to see?

The server will send the content where it is currently running.

What did you see instead?

It is sending content of the directory where the server was previously running and status code 304

@ghost
Copy link
Author

ghost commented Oct 18, 2020

By content i mean directory listing.

@seankhliao
Copy link
Member

can't reproduce, sounds more like a browser problem though?

@ghost ghost closed this as completed Oct 19, 2020
@golang golang locked and limited conversation to collaborators Oct 19, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants