Merge lp:~axwalk/juju-core/httpstorage-cleanup into lp:~go-bot/juju-core/trunk
Proposed by
Andrew Wilkins
Status: | Merged |
---|---|
Approved by: | Andrew Wilkins |
Approved revision: | no longer in the source branch. |
Merged at revision: | 1956 |
Proposed branch: | lp:~axwalk/juju-core/httpstorage-cleanup |
Merge into: | lp:~go-bot/juju-core/trunk |
Diff against target: |
170 lines (+58/-25) 2 files modified
environs/httpstorage/backend.go (+31/-18) environs/httpstorage/backend_test.go (+27/-7) |
To merge this branch: | bzr merge lp:~axwalk/juju-core/httpstorage-cleanup |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+189545@code.launchpad.net |
Commit message
environs/
- s/authoris/
- use net.SplitHostPort, and cater for req.Host
not containing a port
- test HEAD response Location URL, to ensure
it's valid for the storage
Description of the change
environs/
- s/authoris/
- use net.SplitHostPort, and cater for req.Host
not containing a port
- test HEAD response Location URL, to ensure
it's valid for the storage
To post a comment you must log in.
Reviewers: mp+189545_ code.launchpad. net,
Message:
Please take a look.
Description: httpstorage: cleanup
environs/
- s/authoris/ authoriz/
- use net.SplitHostPort, and cater for req.Host
not containing a port
- test HEAD response Location URL, to ensure
it's valid for the storage
https:/ /code.launchpad .net/~axwalk/ juju-core/ httpstorage- cleanup/ +merge/ 189545
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/14483043/
Affected files (+60, -25 lines): httpstorage/ backend. go httpstorage/ backend_ test.go
[revision details]
environs/
environs/
Index: [revision details] 20131004160159- i9eoormyw24etfr 4
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-
+New revision: <email address hidden>
Index: environs/ httpstorage/ backend. go httpstorage/ backend. go' httpstorage/ backend. go 2013-10-04 07:38:49 +0000 httpstorage/ backend. go 2013-10-07 08:24:22 +0000 authenticated. thorized) authenticated. thorized)
=== modified file 'environs/
--- environs/
+++ environs/
@@ -36,9 +36,9 @@
switch req.Method {
case "PUT", "DELETE":
// Don't allow modifying operations if there's an HTTPS backend
- // to handle that, and ensure the user is authorised/
- if s.httpsPort != 0 || !s.authorised(req) {
- http.Error(w, "unauthorised access", http.StatusUnau
+ // to handle that, and ensure the user is authorized/
+ if s.httpsPort != 0 || !s.authorized(req) {
+ http.Error(w, "unauthorized access", http.StatusUnau
return
}
}
@@ -60,30 +60,43 @@
}
}
-// authorised checks that either the storage does not require Query() .Get("authkey" ) == s.authkey
-// authorisation, or the user has specified the correct auth key.
-func (s *storageBackend) authorised(req *http.Request) bool {
+// authorized checks that either the storage does not require
+// authorization, or the user has specified the correct auth key.
+func (s *storageBackend) authorized(req *http.Request) bool {
if s.authkey == "" {
return true
}
return req.URL.
}
+// hostOnly splits a host of the form host, or host:port, rt(host) rt(host + ":0") iter, req LastIndex( hostonly, "]"); i != -1 { LastIndex( hostonly, ":"); i != -1 {
+// into its host and port parts, and returns the host part.
+func hostOnly(host string) (string, error) {
+ hostonly, _, err := net.SplitHostPo
+ if err != nil {
+ // err may be because of missing :port. Checking
+ // the error message is brittle, so let's try
+ // again with ":0" tacked on the end.
+ var err2 error
+ hostonly, _, err = net.SplitHostPo
+ if err2 != nil {
+ // something heinous, return the original error
+ return "", err
+ }
+ }
+ return hostonly, nil
+}
+
// handleHead returns the HTTPS URL for the specified
// path in the Location header.
func (s *storageBackend) handleHead(w http.ResponseWr
*http.Request) {
if s.httpsPort != 0 {
- hostonly := req.Host
- if i := strings.
- // [ipv6]:port
- hostonly = hostonly[:i+1]
- } else {
- // host:port
- if i := strings.
- hostonly = hostonly[:i]
- }
+...