(w http.ResponseWriter, r *http.Request)
| 413 | } |
| 414 | |
| 415 | func (h *handler) handleResource(w http.ResponseWriter, r *http.Request) { |
| 416 | m := resourcePattern.FindStringSubmatch(r.URL.Path) |
| 417 | if m == nil { |
| 418 | http.Error(w, "invalid resource URL", http.StatusBadRequest) |
| 419 | return |
| 420 | } |
| 421 | scanRef, ok := blob.Parse(m[1]) |
| 422 | if !ok { |
| 423 | http.Error(w, fmt.Sprintf("invalid resource blobref: %q", m[1]), http.StatusBadRequest) |
| 424 | return |
| 425 | } |
| 426 | |
| 427 | mediaObject, err := h.fetchScan(scanRef) |
| 428 | if err != nil { |
| 429 | if err == os.ErrNotExist { |
| 430 | http.Error(w, fmt.Sprintf("%v not found", scanRef), http.StatusNotFound) |
| 431 | return |
| 432 | } |
| 433 | httputil.ServeError(w, r, fmt.Errorf("resource %v not found: %v", scanRef, err)) |
| 434 | return |
| 435 | } |
| 436 | |
| 437 | // TODO(mpl): cache and thumbmeta |
| 438 | ih := &camliserver.ImageHandler{ |
| 439 | Fetcher: h.cl, |
| 440 | MaxWidth: search.MaxImageSize, |
| 441 | MaxHeight: search.MaxImageSize, |
| 442 | Square: false, |
| 443 | // TODO(mpl): make the image pkg default to the below when ResizeSem is nil |
| 444 | ResizeSem: syncutil.NewSem(constants.DefaultMaxResizeMem), |
| 445 | } |
| 446 | |
| 447 | if resizeParam := r.FormValue("resize"); resizeParam != "" { |
| 448 | resized, err := strconv.Atoi(resizeParam) |
| 449 | if err != nil { |
| 450 | httputil.ServeError(w, r, fmt.Errorf("bogus resize param %q: %v", resizeParam, err)) |
| 451 | return |
| 452 | } |
| 453 | ih.MaxWidth = resized |
| 454 | ih.MaxHeight = resized |
| 455 | } |
| 456 | ih.ServeHTTP(w, r, mediaObject.contentRef) |
| 457 | } |
| 458 | |
| 459 | func (h *handler) handleMakedoc(w http.ResponseWriter, r *http.Request) { |
| 460 | ctx := r.Context() |
nothing calls this directly
no test coverage detected