Skip to content

Commit

Permalink
Merge pull request #34 from briandowns/issue-33
Browse files Browse the repository at this point in the history
issue-33: update to go mod and support files with spaces
  • Loading branch information
briandowns committed Nov 9, 2019
2 parents 848e1b4 + c1f1367 commit 9b323f1
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 111 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- "1.10"
- "1.13"
- "tip"

# Skip the install step. Don't `go get` dependencies. Only build with the
Expand All @@ -25,7 +25,7 @@ notifications:
# set -e enabled in bash.
before_script:
- GO_FILES=$(find . -iname '*.go' -type f | grep -v /vendor/) # All the .go files, excluding vendor/
- go get github.com/golang/lint/golint # Linter
- go get golang.org/x/lint
- go get github.com/fzipp/gocyclo

# script always run to completion (set +e). All of these code checks are must haves
Expand All @@ -35,3 +35,4 @@ script:
- go test -v ./... # Run all the tests with the race detector enabled
- go vet ./... # go vet is the official Go static analyzer
- golint $(go list ./...) # one last linter

27 changes: 0 additions & 27 deletions Gopkg.lock

This file was deleted.

75 changes: 0 additions & 75 deletions Gopkg.toml

This file was deleted.

9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ LDFLAGS = -ldflags "-X main.gitSHA=$(shell git rev-parse HEAD)"

OS := $(shell uname)

.PHONY: build
build: clean
go build $(LDFLAGS) -o simple-httpd

deps:
dep ensure

.PHONY: test
test:
go test -v .

.PHONY: clean
clean:
go clean
rm -f simple-httpd
rm -f bin/*

.PHONY: install
install: clean
ifeq ($(OS),Darwin)
./build.sh darwin
Expand All @@ -32,5 +33,7 @@ endif
uninstall:
rm -f /usr/local/bin/simple-httpd*

.PHONY: release
release:
./build.sh release

2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

VERSION="0.2"
VERSION="0.3"
ARCHS="darwin linux freebsd windows"

if [ -z $1 ]; then
Expand Down
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/briandowns/simple-httpd

go 1.13

require (
golang.org/x/crypto v0.0.0-20170606163016-e7ba82683099
golang.org/x/net v0.0.0-20170610001149-1a68b1313cf4
golang.org/x/text v0.0.0-20170609090223-210eee5cf732
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
golang.org/x/crypto v0.0.0-20170606163016-e7ba82683099 h1:I4qkV9tPncVkQYMfrPH2Puyw2/JzngpFdj4yRu95AgM=
golang.org/x/crypto v0.0.0-20170606163016-e7ba82683099/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/net v0.0.0-20170610001149-1a68b1313cf4/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/text v0.0.0-20170609090223-210eee5cf732/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
14 changes: 11 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func setHeaders(w http.ResponseWriter) {
}

// isIndexFile determines if the given file is one
// of the accepted index files
// of the accepted index files.
func isIndexFile(file string) bool {
for _, s := range indexHTMLFiles {
if s == file {
Expand Down Expand Up @@ -133,7 +133,13 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}

// check if we have a file with spaces in the name and
// replace the %20 with an actual space.
escapedPath := parsedURL.EscapedPath()
if strings.Contains(escapedPath, "%20") {
escapedPath = strings.ReplaceAll(escapedPath, "%20", " ")
}

fullpath := filepath.Join(h.Directory, escapedPath[1:])

file, err := os.Open(fullpath)
Expand Down Expand Up @@ -281,6 +287,8 @@ Examples:
simple-httpd -p 80 -l example.com enable HTTPS with Let's Encrypt. https://example.com
`

const warmUpDelay = 10

func main() {
var port int
var le string
Expand Down Expand Up @@ -376,11 +384,11 @@ func main() {
log.Fatal(err)
}
}()
time.Sleep(time.Millisecond * 10) // give a little warmup time to the TLS
time.Sleep(time.Millisecond * warmUpDelay) // give a little warmup time to the TLS
fmt.Printf("Serving HTTP on 0.0.0.0 port %v, HTTPS on port %v...\n", h.Port, tlsPort)
} else {
go func() {
time.Sleep(time.Millisecond * 10) // give a little warmup time to the HTTP
time.Sleep(time.Millisecond * warmUpDelay) // give a little warmup time to the HTTP
fmt.Printf("Serving HTTP on 0.0.0.0 port %v ...\n", h.Port)
}()
}
Expand Down

0 comments on commit 9b323f1

Please sign in to comment.