good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
chat
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
github
tinode
chat
Commits
2072f031
Commit
2072f031
authored
Apr 15, 2023
by
or-else
Browse files
Options
Downloads
Patches
Plain Diff
fix web attachment downloads by adding Content-Disposition header
parent
dda74cdd
Branches
Branches containing commit
Tags
v0.22.6
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/hdl_files.go
+5
-2
5 additions, 2 deletions
server/hdl_files.go
server/media/s3/s3.go
+9
-3
9 additions, 3 deletions
server/media/s3/s3.go
with
14 additions
and
5 deletions
server/hdl_files.go
+
5
−
2
View file @
2072f031
...
@@ -15,6 +15,7 @@ import (
...
@@ -15,6 +15,7 @@ import (
"io"
"io"
"math/rand"
"math/rand"
"net/http"
"net/http"
"strconv"
"strings"
"strings"
"time"
"time"
...
@@ -133,7 +134,9 @@ func largeFileServe(wrt http.ResponseWriter, req *http.Request) {
...
@@ -133,7 +134,9 @@ func largeFileServe(wrt http.ResponseWriter, req *http.Request) {
defer
rsc
.
Close
()
defer
rsc
.
Close
()
wrt
.
Header
()
.
Set
(
"Content-Type"
,
fd
.
MimeType
)
wrt
.
Header
()
.
Set
(
"Content-Type"
,
fd
.
MimeType
)
if
isAttachment
,
_
:=
strconv
.
ParseBool
(
req
.
URL
.
Query
()
.
Get
(
"asatt"
));
isAttachment
{
wrt
.
Header
()
.
Set
(
"Content-Disposition"
,
"attachment"
)
wrt
.
Header
()
.
Set
(
"Content-Disposition"
,
"attachment"
)
}
http
.
ServeContent
(
wrt
,
req
,
""
,
fd
.
UpdatedAt
,
rsc
)
http
.
ServeContent
(
wrt
,
req
,
""
,
fd
.
UpdatedAt
,
rsc
)
logs
.
Info
.
Println
(
"media serve: OK, uid="
,
uid
)
logs
.
Info
.
Println
(
"media serve: OK, uid="
,
uid
)
...
@@ -265,7 +268,7 @@ func largeFileReceive(wrt http.ResponseWriter, req *http.Request) {
...
@@ -265,7 +268,7 @@ func largeFileReceive(wrt http.ResponseWriter, req *http.Request) {
}
}
mimeType
:=
http
.
DetectContentType
(
buff
)
mimeType
:=
http
.
DetectContentType
(
buff
)
// If DetectContentType fail
ed
, use
user
-provided content type.
// If DetectContentType fail
s
, use
client
-provided content type.
if
mimeType
==
"application/octet-stream"
{
if
mimeType
==
"application/octet-stream"
{
if
contentType
:=
header
.
Header
.
Get
(
"Content-Type"
);
contentType
!=
""
{
if
contentType
:=
header
.
Header
.
Get
(
"Content-Type"
);
contentType
!=
""
{
mimeType
=
contentType
mimeType
=
contentType
...
...
This diff is collapsed.
Click to expand it.
server/media/s3/s3.go
+
9
−
3
View file @
2072f031
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"io"
"io"
"mime"
"mime"
"net/http"
"net/http"
"strconv"
"sync/atomic"
"sync/atomic"
"time"
"time"
...
@@ -172,10 +173,15 @@ func (ah *awshandler) Headers(req *http.Request, serve bool) (http.Header, int,
...
@@ -172,10 +173,15 @@ func (ah *awshandler) Headers(req *http.Request, serve bool) (http.Header, int,
var
awsReq
*
request
.
Request
var
awsReq
*
request
.
Request
if
req
.
Method
==
http
.
MethodGet
{
if
req
.
Method
==
http
.
MethodGet
{
var
contentDisposition
*
string
if
isAttachment
,
_
:=
strconv
.
ParseBool
(
req
.
URL
.
Query
()
.
Get
(
"asatt"
));
isAttachment
{
contentDisposition
=
aws
.
String
(
"attachment"
)
}
awsReq
,
_
=
ah
.
svc
.
GetObjectRequest
(
&
s3
.
GetObjectInput
{
awsReq
,
_
=
ah
.
svc
.
GetObjectRequest
(
&
s3
.
GetObjectInput
{
Bucket
:
aws
.
String
(
ah
.
conf
.
BucketName
),
Bucket
:
aws
.
String
(
ah
.
conf
.
BucketName
),
Key
:
aws
.
String
(
fid
.
String32
()),
Key
:
aws
.
String
(
fid
.
String32
()),
ResponseContentType
:
aws
.
String
(
fd
.
MimeType
),
ResponseContentType
:
aws
.
String
(
fd
.
MimeType
),
ResponseContentDisposition
:
contentDisposition
,
})
})
}
else
if
req
.
Method
==
http
.
MethodHead
{
}
else
if
req
.
Method
==
http
.
MethodHead
{
awsReq
,
_
=
ah
.
svc
.
HeadObjectRequest
(
&
s3
.
HeadObjectInput
{
awsReq
,
_
=
ah
.
svc
.
HeadObjectRequest
(
&
s3
.
HeadObjectInput
{
...
...
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