Repository: ollama
Issue: Model pulling behind proxy index out of range
Labels: bug

### What is the issue?

Hi,

I'm getting the following error when trying to go through corpo proxy when downloading models with ollama pull:


```plaintext
panic: runtime error: index out of range [0] with length 0


goroutine 7 [running]:
github.com/ollama/ollama/server.(*blobDownload).Prepare(0xc0001cf1f0, {0x55efb74bd430, 0xc00042a4b0}, 0xc0000e1a70, 0xc000431480)
        github.com/ollama/ollama/server/download.go:175 +0x539
github.com/ollama/ollama/server.downloadBlob({0x55efb74bd430, 0xc00042a4b0}, {{{0x55efb708726e, 0x5}, {0x55efb709b519, 0x12}, {0x55efb708fd4b, 0x7}, {0xc000016560, 0x8}, ...}, ...})
        github.com/ollama/ollama/server/download.go:489 +0x4da
github.com/ollama/ollama/server.PullModel({0x55efb74bd430, 0xc00042a4b0}, {0xc000016560, 0xb}, 0xc000431480, 0xc0002824f0)
        github.com/ollama/ollama/server/images.go:889 +0x771
github.com/ollama/ollama/server.(*Server).PullHandler.func1()
        github.com/ollama/ollama/server/routes.go:595 +0x197
created by github.com/ollama/ollama/server.(*Server).PullHandler in goroutine 29
        github.com/ollama/ollama/server/routes.go:582 +0x691

```

With GODEBUG=http2debug=2 set:
time=2025-01-13T10:29:35.304Z level=INFO source=h2_bundle.go:10279 msg="http2: Transport failed to get client conn for registry.ollama.ai:443: http2: no cached connection was available"



It occurs both when running from docker container or from downloaded released binary on Ubuntu. When running  inside container, the HTTPS_PROXY is set, the container is updated with certificates.
wget or curl inside this container to some registry urls, e.g. https://registry.ollama.ai/v2/library/tinnyllama/blobs/sha256:2af3b81862c6be03c769683af18efdadb2c33f60ff32ab6f83e42c043d6c7816, works fine. 


## Full log

```plaintext

docker logs ollama
2025/01/13 10:29:05 routes.go:1259: INFO server config env="map[CUDA_VISIBLE_DEVICES: GPU_DEVICE_ORDINAL: HIP_VISIBLE_DEVICES: HSA_OVERRIDE_GFX_VERSION: HTTPS_PROXY:proxyx.cn.:8080 HTTP_PROXY: NO_PROXY: OLLAMA_DEBUG:false OLLAMA_FLASH_ATTENTION:false OLLAMA_GPU_OVERHEAD:0 OLLAMA_HOST:http://0.0.0.0:11434 OLLAMA_INTEL_GPU:false OLLAMA_KEEP_ALIVE:5m0s OLLAMA_KV_CACHE_TYPE: OLLAMA_LLM_LIBRARY: OLLAMA_LOAD_TIMEOUT:5m0s OLLAMA_MAX_LOADED_MODELS:0 OLLAMA_MAX_QUEUE:512 OLLAMA_MODELS:/root/.ollama/models OLLAMA_MULTIUSER_CACHE:false OLLAMA_NOHISTORY:false OLLAMA_NOPRUNE:false OLLAMA_NUM_PARALLEL:0 OLLAMA_ORIGINS:[http://localhost https://localhost http://localhost:* https://localhost:* http://127.0.0.1 https://127.0.0.1 http://127.0.0.1:* https://127.0.0.1:* http://0.0.0.0 https://0.0.0.0 http://0.0.0.0:* https://0.0.0.0:* app://* file://* tauri://* vscode-webview://*] OLLAMA_SCHED_SPREAD:false ROCR_VISIBLE_DEVICES: http_proxy: https_proxy: no_proxy:]"
time=2025-01-13T10:29:05.927Z level=INFO source=images.go:757 msg="total blobs: 0"
time=2025-01-13T10:29:05.927Z level=INFO source=images.go:764 msg="total unused blobs removed: 0"
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[GIN-debug] POST   /api/pull                 --> github.com/ollama/ollama/server.(*Server).PullHandler-fm (5 handlers)
[GIN-debug] POST   /api/generate             --> github.com/ollama/ollama/server.(*Server).GenerateHandler-fm (5 handlers)
[GIN-debug] POST   /api/chat                 --> github.com/ollama/ollama/server.(*Server).ChatHandler-fm (5 handlers)
[GIN-debug] POST   /api/embed                --> github.com/ollama/ollama/server.(*Server).EmbedHandler-fm (5 handlers)
[GIN-debug] POST   /api/embeddings           --> github.com/ollama/ollama/server.(*Server).EmbeddingsHandler-fm (5 handlers)
[GIN-debug] POST   /api/create               --> github.com/ollama/ollama/server.(*Server).CreateHandler-fm (5 handlers)
[GIN-debug] POST   /api/push                 --> github.com/ollama/ollama/server.(*Server).PushHandler-fm (5 handlers)
[GIN-debug] POST   /api/copy                 --> github.com/ollama/ollama/server.(*Server).CopyHandler-fm (5 handlers)
[GIN-debug] DELETE /api/delete               --> github.com/ollama/ollama/server.(*Server).DeleteHandler-fm (5 handlers)
[GIN-debug] POST   /api/show                 --> github.com/ollama/ollama/server.(*Server).ShowHandler-fm (5 handlers)
[GIN-debug] POST   /api/blobs/:digest        --> github.com/ollama/ollama/server.(*Server).CreateBlobHandler-fm (5 handlers)
[GIN-debug] HEAD   /api/blobs/:digest        --> github.com/ollama/ollama/server.(*Server).HeadBlobHandler-fm (5 handlers)
[GIN-debug] GET    /api/ps                   --> github.com/ollama/ollama/server.(*Server).PsHandler-fm (5 handlers)
[GIN-debug] POST   /v1/chat/completions      --> github.com/ollama/ollama/server.(*Server).ChatHandler-fm (6 handlers)
[GIN-debug] POST   /v1/completions           --> github.com/ollama/ollama/server.(*Server).GenerateHandler-fm (6 handlers)
[GIN-debug] POST   /v1/embeddings            --> github.com/ollama/ollama/server.(*Server).EmbedHandler-fm (6 handlers)
[GIN-debug] GET    /v1/models                --> github.com/ollama/ollama/server.(*Server).ListHandler-fm (6 handlers)
[GIN-debug] GET    /v1/models/:model         --> github.com/ollama/ollama/server.(*Server).ShowHandler-fm (6 handlers)
[GIN-debug] GET    /                         --> github.com/ollama/ollama/server.(*Server).GenerateRoutes.func1 (5 handlers)
[GIN-debug] GET    /api/tags                 --> github.com/ollama/ollama/server.(*Server).ListHandler-fm (5 handlers)
[GIN-debug] GET    /api/version              --> github.com/ollama/ollama/server.(*Server).GenerateRoutes.func2 (5 handlers)
[GIN-debug] HEAD   /                         --> github.com/ollama/ollama/server.(*Server).GenerateRoutes.func1 (5 handlers)
[GIN-debug] HEAD   /api/tags                 --> github.com/ollama/ollama/server.(*Server).ListHandler-fm (5 handlers)
[GIN-debug] HEAD   /api/version              --> github.com/ollama/ollama/server.(*Server).GenerateRoutes.func2 (5 handlers)
time=2025-01-13T10:29:05.928Z level=INFO source=routes.go:1310 msg="Listening on [::]:11434 (version 0.5.4-0-g2ddc32d-dirty)"
time=2025-01-13T10:29:05.929Z level=INFO source=routes.go:1339 msg="Dynamic LLM libraries" runners="[cpu_avx cpu_avx2 cuda_v11_avx cuda_v12_avx cpu]"
time=2025-01-13T10:29:05.929Z level=INFO source=gpu.go:226 msg="looking for compatible GPUs"
time=2025-01-13T10:29:05.934Z level=INFO source=gpu.go:392 msg="no compatible GPUs were discovered"
time=2025-01-13T10:29:05.934Z level=INFO source=types.go:131 msg="inference compute" id=0 library=cpu variant=avx compute="" driver=0.0 name="" total="7.8 GiB" available="6.0 GiB"
[GIN] 2025/01/13 - 10:29:35 | 200 |     245.408µs |       127.0.0.1 | HEAD     "/"
time=2025-01-13T10:29:35.304Z level=INFO source=h2_bundle.go:10279 msg="http2: Transport failed to get client conn for registry.ollama.ai:443: http2: no cached connection was available"
time=2025-01-13T10:29:35.895Z level=INFO source=h2_bundle.go:10279 msg="http2: Transport failed to get client conn for registry.ollama.ai:443: http2: no cached connection was available"
time=2025-01-13T10:29:36.156Z level=INFO source=h2_bundle.go:10279 msg="http2: Transport failed to get client conn for registry.ollama.ai:443: http2: no cached connection was available"
time=2025-01-13T10:29:36.466Z level=INFO source=h2_bundle.go:10279 msg="http2: Transport failed to get client conn for registry.ollama.ai:443: http2: no cached connection was available"
panic: runtime error: index out of range [0] with length 0

goroutine 7 [running]:
github.com/ollama/ollama/server.(*blobDownload).Prepare(0xc0001cf1f0, {0x55efb74bd430, 0xc00042a4b0}, 0xc0000e1a70, 0xc000431480)
        github.com/ollama/ollama/server/download.go:175 +0x539
github.com/ollama/ollama/server.downloadBlob({0x55efb74bd430, 0xc00042a4b0}, {{{0x55efb708726e, 0x5}, {0x55efb709b519, 0x12}, {0x55efb708fd4b, 0x7}, {0xc000016560, 0x8}, ...}, ...})
        github.com/ollama/ollama/server/download.go:489 +0x4da
github.com/ollama/ollama/server.PullModel({0x55efb74bd430, 0xc00042a4b0}, {0xc000016560, 0xb}, 0xc000431480, 0xc0002824f0)
        github.com/ollama/ollama/server/images.go:889 +0x771
github.com/ollama/ollama/server.(*Server).PullHandler.func1()
        github.com/ollama/ollama/server/routes.go:595 +0x197
created by github.com/ollama/ollama/server.(*Server).PullHandler in goroutine 29
        github.com/ollama/ollama/server/routes.go:582 +0x691


```

### OS

Linux, Docker

### GPU

Intel

### CPU

Intel

### Ollama version

0.5.4-0-g2ddc32d-dirty