| 277 | } |
| 278 | |
| 279 | func (h *shareHandler) serveHTTP(rw http.ResponseWriter, req *http.Request) error { |
| 280 | var err error |
| 281 | pathSuffix := httputil.PathSuffix(req) |
| 282 | if len(pathSuffix) == 0 { |
| 283 | // This happens during testing because we don't go through PrefixHandler |
| 284 | pathSuffix = strings.TrimLeft(req.URL.Path, "/") |
| 285 | } |
| 286 | pathParts := strings.SplitN(pathSuffix, "/", 2) |
| 287 | blobRef, ok := blob.Parse(pathParts[0]) |
| 288 | if !ok { |
| 289 | err = &shareError{code: invalidURL, response: badRequest, |
| 290 | message: fmt.Sprintf("Malformed share pathSuffix: %s", pathSuffix)} |
| 291 | } else { |
| 292 | err = h.handleGetViaSharing(rw, req, blobRef) |
| 293 | } |
| 294 | if se, ok := err.(*shareError); ok { |
| 295 | switch se.response { |
| 296 | case badRequest: |
| 297 | httputil.BadRequestError(rw, "%s", err) |
| 298 | case unauthorizedRequest: |
| 299 | if h.log { |
| 300 | log.Print(err) |
| 301 | } |
| 302 | auth.SendUnauthorized(rw, req) |
| 303 | } |
| 304 | } |
| 305 | return err |
| 306 | } |
| 307 | |
| 308 | func (h *shareHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { |
| 309 | h.serveHTTP(rw, req) |