Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
56e87cec
Commit
56e87cec
authored
Aug 16, 2023
by
Michael Yang
Browse files
images: remove body copies
parent
5ee61164
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
35 deletions
+2
-35
server/images.go
server/images.go
+2
-35
No files found.
server/images.go
View file @
56e87cec
...
...
@@ -1222,15 +1222,6 @@ func uploadBlobChunked(ctx context.Context, mp ModelPath, url string, layer *Lay
}
func
makeRequest
(
ctx
context
.
Context
,
method
,
url
string
,
headers
map
[
string
]
string
,
body
io
.
Reader
,
regOpts
*
RegistryOptions
)
(
*
http
.
Response
,
error
)
{
retryCtx
:=
ctx
.
Value
(
"retries"
)
var
retries
int
var
ok
bool
if
retries
,
ok
=
retryCtx
.
(
int
);
ok
{
if
retries
>
MaxRetries
{
return
nil
,
fmt
.
Errorf
(
"maximum retries hit; are you sure you have access to this resource?"
)
}
}
if
!
strings
.
HasPrefix
(
url
,
"http"
)
{
if
regOpts
.
Insecure
{
url
=
"http://"
+
url
...
...
@@ -1239,18 +1230,7 @@ func makeRequest(ctx context.Context, method, url string, headers map[string]str
}
}
// make a copy of the body in case we need to try the call to makeRequest again
var
buf
bytes
.
Buffer
if
body
!=
nil
{
_
,
err
:=
io
.
Copy
(
&
buf
,
body
)
if
err
!=
nil
{
return
nil
,
err
}
}
bodyCopy
:=
bytes
.
NewReader
(
buf
.
Bytes
())
req
,
err
:=
http
.
NewRequest
(
method
,
url
,
bodyCopy
)
req
,
err
:=
http
.
NewRequestWithContext
(
ctx
,
method
,
url
,
body
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -1274,25 +1254,12 @@ func makeRequest(ctx context.Context, method, url string, headers map[string]str
return
nil
},
}
resp
,
err
:=
client
.
Do
(
req
)
if
err
!=
nil
{
return
nil
,
err
}
// if the request is unauthenticated, try to authenticate and make the request again
if
resp
.
StatusCode
==
http
.
StatusUnauthorized
{
auth
:=
resp
.
Header
.
Get
(
"Www-Authenticate"
)
authRedir
:=
ParseAuthRedirectString
(
string
(
auth
))
token
,
err
:=
getAuthToken
(
ctx
,
authRedir
,
regOpts
)
if
err
!=
nil
{
return
nil
,
err
}
regOpts
.
Token
=
token
bodyCopy
=
bytes
.
NewReader
(
buf
.
Bytes
())
ctx
=
context
.
WithValue
(
ctx
,
"retries"
,
retries
+
1
)
return
makeRequest
(
ctx
,
method
,
url
,
headers
,
bodyCopy
,
regOpts
)
}
return
resp
,
nil
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment