Skip to content

Commit

Permalink
Release 1.4.3: Fixed redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
Michel Casabianca committed Aug 18, 2015
2 parents 8341dd3 + f55eed8 commit e12b299
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Semantic changelog: https://github.com/c4s4/changelog

- version: 1.4.3
date: 2015-08-18
summary: Fixed redirection
fixed:
- "Fixed redirection so that protocol (http or https) is kept."

- version: 1.4.2
date: 2015-07-31
summary: Added configuration field overwrite
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ The configuration file should look like this:
# The URL path
path: simple
# Redirection when not found
shop: http://pypi.python.org/simple
shop: pypi.python.org/simple
# Tells if we can overwrite an existing package
overwrite: false
# List of users and their MD5 hashed password
Expand Down Expand Up @@ -149,7 +149,7 @@ This is the URL path that the server will listen. Default value is *simple*, thu

### shop

This is the URL of the public package repository, aka <http://pypi.python.org/simple>. This should not be changed.
This is the URL of the public package repository without protocol (*http* or *https*), such as *pypi.python.org/simple*. This should not be changed.

### overwrite

Expand Down
16 changes: 12 additions & 4 deletions cheeseshop.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,21 @@ func listRoot(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(LIST_TAIL))
}

func redirect(url string, w http.ResponseWriter, r *http.Request) {
if r.TLS == nil {
url = "http://" + url
} else {
url = "https://" + url
}
log.Printf("Redirecting to %s", url)
http.Redirect(w, r, url, http.StatusFound)
}

func listDirectory(dir string, w http.ResponseWriter, r *http.Request) {
directory := filepath.Join(config.Root, dir)
if _, err := os.Stat(directory); os.IsNotExist(err) {
url := config.Shop + "/" + dir
log.Printf("Redirecting to %s", url)
http.Redirect(w, r, url, http.StatusFound)
redirect(url, w, r)
return
}
log.Printf("Listing directory %s", directory)
Expand All @@ -78,8 +87,7 @@ func servePackage(dir, file string, w http.ResponseWriter, r *http.Request) {
filename := filepath.Join(config.Root, dir, file)
if _, err := os.Stat(filename); os.IsNotExist(err) {
url := config.Shop + "/" + dir + "/" + file
log.Printf("Redirecting to %s", url)
http.Redirect(w, r, url, http.StatusFound)
redirect(url, w, r)
return
}
log.Printf("Serving file %s", filename)
Expand Down
2 changes: 1 addition & 1 deletion etc/cheeseshop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ https: 443
# The URL path
path: simple
# Redirection when not found
shop: http://pypi.python.org/simple
shop: pypi.python.org/simple
# Tells if we can overwrite an existing package
overwrite: false
# List of users and their MD5 hashed password
Expand Down

0 comments on commit e12b299

Please sign in to comment.