Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fachstellen-proxy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OZG-Cloud
app
fachstellen-proxy
Commits
6ea75f2e
Commit
6ea75f2e
authored
9 months ago
by
OZGCloud
Browse files
Options
Downloads
Patches
Plain Diff
OZG-6514 Umstellung File Download Response
parent
31632589
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
internal/server/handler.go
+7
-31
7 additions, 31 deletions
internal/server/handler.go
with
7 additions
and
31 deletions
internal/server/handler.go
+
7
−
31
View file @
6ea75f2e
...
@@ -36,16 +36,13 @@ import (
...
@@ -36,16 +36,13 @@ import (
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/status"
"google.golang.org/grpc/status"
"io"
"io"
"mime/multipart"
"net/http"
"net/http"
)
)
const
(
const
(
fileIdParam
=
"id"
fileIdParam
=
"id"
samlTokenParam
=
"samlToken"
samlTokenParam
=
"samlToken"
fileFormKey
=
"file"
contentTypeHeaderKey
=
"Content-Type"
contentTypeHeaderKey
=
"Content-Type"
contentDispositionHeaderKey
=
"Content-Disposition"
)
)
func
RegisterHomeEndpoint
(
mux
*
runtime
.
ServeMux
)
{
func
RegisterHomeEndpoint
(
mux
*
runtime
.
ServeMux
)
{
...
@@ -94,7 +91,10 @@ func getFileHandler(w http.ResponseWriter, r *http.Request, vars map[string]stri
...
@@ -94,7 +91,10 @@ func getFileHandler(w http.ResponseWriter, r *http.Request, vars map[string]stri
return
return
}
}
err
=
writeMultipartResponse
(
w
,
fileBuffer
)
w
.
Header
()
.
Set
(
contentTypeHeaderKey
,
"application/octet-stream"
)
w
.
WriteHeader
(
http
.
StatusOK
)
_
,
err
=
fileBuffer
.
WriteTo
(
w
)
if
err
!=
nil
{
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
}
}
...
@@ -135,30 +135,6 @@ func fetchFileFromGrpc(ctx context.Context, fileId string, samlToken string, grp
...
@@ -135,30 +135,6 @@ func fetchFileFromGrpc(ctx context.Context, fileId string, samlToken string, grp
return
&
fileBuffer
,
nil
return
&
fileBuffer
,
nil
}
}
func
writeMultipartResponse
(
w
http
.
ResponseWriter
,
fileBuffer
*
bytes
.
Buffer
)
error
{
w
.
Header
()
.
Set
(
contentTypeHeaderKey
,
"multipart/form-data"
)
w
.
Header
()
.
Set
(
contentDispositionHeaderKey
,
`attachment; filename="file"`
)
w
.
WriteHeader
(
http
.
StatusOK
)
mw
:=
multipart
.
NewWriter
(
w
)
part
,
err
:=
mw
.
CreateFormFile
(
fileFormKey
,
fileFormKey
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error creating multipart form file"
)
}
_
,
err
=
fileBuffer
.
WriteTo
(
part
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error writing file data to multipart"
)
}
err
=
mw
.
Close
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error closing multipart writer"
)
}
return
nil
}
func
ErrorHandler
(
ctx
context
.
Context
,
mux
*
runtime
.
ServeMux
,
marshaler
runtime
.
Marshaler
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
err
error
)
{
func
ErrorHandler
(
ctx
context
.
Context
,
mux
*
runtime
.
ServeMux
,
marshaler
runtime
.
Marshaler
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
err
error
)
{
st
,
ok
:=
status
.
FromError
(
err
)
st
,
ok
:=
status
.
FromError
(
err
)
if
!
ok
{
if
!
ok
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment