Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
0d830e5a
Commit
0d830e5a
authored
Oct 23, 2014
by
Matt Bell
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
server/http: Set Content-Type header based on command output
parent
12b0ebff
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
0 deletions
+11
-0
server/http/http.go
server/http/http.go
+11
-0
No files found.
server/http/http.go
View file @
0d830e5a
...
@@ -103,6 +103,16 @@ func (i *apiHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
...
@@ -103,6 +103,16 @@ func (i *apiHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
req
:=
cmds
.
NewRequest
(
path
,
opts
,
nil
,
nil
)
req
:=
cmds
.
NewRequest
(
path
,
opts
,
nil
,
nil
)
res
:=
commands
.
Root
.
Call
(
req
)
res
:=
commands
.
Root
.
Call
(
req
)
// set the Content-Type based on res output
if
_
,
ok
:=
res
.
Value
()
.
(
io
.
Reader
);
ok
{
// TODO: set based on actual Content-Type of file
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/octet-stream"
)
}
else
{
// TODO: get proper MIME type for encoding from multicodec lib
enc
,
_
:=
req
.
Option
(
cmds
.
EncShort
)
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/"
+
enc
.
(
string
))
}
// if response contains an error, write an HTTP error status code
// if response contains an error, write an HTTP error status code
if
e
:=
res
.
Error
();
e
!=
nil
{
if
e
:=
res
.
Error
();
e
!=
nil
{
if
e
.
Code
==
cmds
.
ErrClient
{
if
e
.
Code
==
cmds
.
ErrClient
{
...
@@ -115,6 +125,7 @@ func (i *apiHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
...
@@ -115,6 +125,7 @@ func (i *apiHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
_
,
err
=
io
.
Copy
(
w
,
res
)
_
,
err
=
io
.
Copy
(
w
,
res
)
if
err
!=
nil
{
if
err
!=
nil
{
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
w
.
Header
()
.
Set
(
"Content-Type"
,
"text/plain"
)
w
.
Write
([]
byte
(
err
.
Error
()))
w
.
Write
([]
byte
(
err
.
Error
()))
}
}
}
}
...
...
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