Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
02fef51f
Commit
02fef51f
authored
Oct 20, 2021
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set Content-Length header on Dependency Proxy injection
Without it the progress bar is not displayed
parent
ad0085ce
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
4 deletions
+6
-4
workhorse/internal/dependencyproxy/dependencyproxy.go
workhorse/internal/dependencyproxy/dependencyproxy.go
+2
-2
workhorse/internal/dependencyproxy/dependencyproxy_test.go
workhorse/internal/dependencyproxy/dependencyproxy_test.go
+4
-2
No files found.
workhorse/internal/dependencyproxy/dependencyproxy.go
View file @
02fef51f
...
...
@@ -87,6 +87,8 @@ func (p *Injector) Inject(w http.ResponseWriter, r *http.Request, sendData strin
return
}
w
.
Header
()
.
Set
(
"Content-Length"
,
dependencyResponse
.
Header
.
Get
(
"Content-Length"
))
teeReader
:=
io
.
TeeReader
(
dependencyResponse
.
Body
,
w
)
saveFileRequest
,
err
:=
http
.
NewRequestWithContext
(
r
.
Context
(),
"POST"
,
r
.
URL
.
String
()
+
"/upload"
,
teeReader
)
if
err
!=
nil
{
...
...
@@ -95,8 +97,6 @@ func (p *Injector) Inject(w http.ResponseWriter, r *http.Request, sendData strin
saveFileRequest
.
Header
=
helper
.
HeaderClone
(
r
.
Header
)
saveFileRequest
.
ContentLength
=
dependencyResponse
.
ContentLength
w
.
Header
()
.
Del
(
"Content-Length"
)
nrw
:=
&
nullResponseWriter
{
header
:
make
(
http
.
Header
)}
p
.
uploadHandler
.
ServeHTTP
(
nrw
,
saveFileRequest
)
...
...
workhorse/internal/dependencyproxy/dependencyproxy_test.go
View file @
02fef51f
...
...
@@ -33,7 +33,7 @@ func (f *fakeUploadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
type
errWriter
struct
{
writes
int
}
func
(
w
*
errWriter
)
Header
()
http
.
Header
{
return
nil
}
func
(
w
*
errWriter
)
Header
()
http
.
Header
{
return
make
(
http
.
Header
)
}
func
(
w
*
errWriter
)
WriteHeader
(
h
int
)
{}
// First call of Write function succeeds while all the subsequent ones fail
...
...
@@ -112,8 +112,9 @@ func TestInject(t *testing.T) {
func
TestSuccessfullRequest
(
t
*
testing
.
T
)
{
content
:=
[]
byte
(
"result"
)
contentLength
:=
strconv
.
Itoa
(
len
(
content
))
originResourceServer
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
Header
()
.
Set
(
"Content-Length"
,
strconv
.
Itoa
(
len
(
content
))
)
w
.
Header
()
.
Set
(
"Content-Length"
,
contentLength
)
w
.
Write
(
content
)
}))
...
...
@@ -135,6 +136,7 @@ func TestSuccessfullRequest(t *testing.T) {
require
.
Equal
(
t
,
200
,
response
.
Code
)
require
.
Equal
(
t
,
string
(
content
),
response
.
Body
.
String
())
require
.
Equal
(
t
,
contentLength
,
response
.
Header
()
.
Get
(
"Content-Length"
))
}
func
TestIncorrectSendData
(
t
*
testing
.
T
)
{
...
...
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