Skip to content

Commit e12b299

Browse files
author
Michel Casabianca
committed
Release 1.4.3: Fixed redirection
2 parents 8341dd3 + f55eed8 commit e12b299

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

Diff for: CHANGELOG.yml

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Semantic changelog: https://github.com/c4s4/changelog
22

3+
- version: 1.4.3
4+
date: 2015-08-18
5+
summary: Fixed redirection
6+
fixed:
7+
- "Fixed redirection so that protocol (http or https) is kept."
8+
39
- version: 1.4.2
410
date: 2015-07-31
511
summary: Added configuration field overwrite

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ The configuration file should look like this:
8686
# The URL path
8787
path: simple
8888
# Redirection when not found
89-
shop: http://pypi.python.org/simple
89+
shop: pypi.python.org/simple
9090
# Tells if we can overwrite an existing package
9191
overwrite: false
9292
# List of users and their MD5 hashed password
@@ -149,7 +149,7 @@ This is the URL path that the server will listen. Default value is *simple*, thu
149149

150150
### shop
151151

152-
This is the URL of the public package repository, aka <http://pypi.python.org/simple>. This should not be changed.
152+
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.
153153

154154
### overwrite
155155

Diff for: cheeseshop.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,21 @@ func listRoot(w http.ResponseWriter, r *http.Request) {
5353
w.Write([]byte(LIST_TAIL))
5454
}
5555

56+
func redirect(url string, w http.ResponseWriter, r *http.Request) {
57+
if r.TLS == nil {
58+
url = "http://" + url
59+
} else {
60+
url = "https://" + url
61+
}
62+
log.Printf("Redirecting to %s", url)
63+
http.Redirect(w, r, url, http.StatusFound)
64+
}
65+
5666
func listDirectory(dir string, w http.ResponseWriter, r *http.Request) {
5767
directory := filepath.Join(config.Root, dir)
5868
if _, err := os.Stat(directory); os.IsNotExist(err) {
5969
url := config.Shop + "/" + dir
60-
log.Printf("Redirecting to %s", url)
61-
http.Redirect(w, r, url, http.StatusFound)
70+
redirect(url, w, r)
6271
return
6372
}
6473
log.Printf("Listing directory %s", directory)
@@ -78,8 +87,7 @@ func servePackage(dir, file string, w http.ResponseWriter, r *http.Request) {
7887
filename := filepath.Join(config.Root, dir, file)
7988
if _, err := os.Stat(filename); os.IsNotExist(err) {
8089
url := config.Shop + "/" + dir + "/" + file
81-
log.Printf("Redirecting to %s", url)
82-
http.Redirect(w, r, url, http.StatusFound)
90+
redirect(url, w, r)
8391
return
8492
}
8593
log.Printf("Serving file %s", filename)

Diff for: etc/cheeseshop.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ https: 443
1111
# The URL path
1212
path: simple
1313
# Redirection when not found
14-
shop: http://pypi.python.org/simple
14+
shop: pypi.python.org/simple
1515
# Tells if we can overwrite an existing package
1616
overwrite: false
1717
# List of users and their MD5 hashed password

0 commit comments

Comments
 (0)