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
bb9493ac
Commit
bb9493ac
authored
Oct 28, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
content type on command responses default to text
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
3c8c729a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
7 deletions
+13
-7
commands/http/handler.go
commands/http/handler.go
+13
-7
No files found.
commands/http/handler.go
View file @
bb9493ac
...
...
@@ -180,7 +180,11 @@ func guessMimeType(res cmds.Response) (string, error) {
return
""
,
errors
.
New
(
"no encoding option set"
)
}
return
mimeTypes
[
enc
],
nil
if
m
,
ok
:=
mimeTypes
[
enc
];
ok
{
return
m
,
nil
}
return
mimeTypes
[
cmds
.
JSON
],
nil
}
func
sendResponse
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
res
cmds
.
Response
,
req
cmds
.
Request
)
{
...
...
@@ -217,10 +221,9 @@ func sendResponse(w http.ResponseWriter, r *http.Request, res cmds.Response, req
}
if
_
,
ok
:=
res
.
Output
()
.
(
io
.
Reader
);
ok
{
// we don't set the Content-Type for streams, so that browsers can MIME-sniff the type themselves
// we set this header so clients have a way to know this is an output stream
// (not marshalled command output)
mime
=
""
// set streams output type to text to avoid issues with browsers rendering
// html pages on priveleged api ports
mime
=
"text/plain"
h
.
Set
(
streamHeader
,
"1"
)
}
...
...
@@ -235,9 +238,12 @@ func sendResponse(w http.ResponseWriter, r *http.Request, res cmds.Response, req
h
.
Set
(
channelHeader
,
"1"
)
}
if
mime
!=
""
{
h
.
Set
(
contentTypeHeader
,
mime
)
// catch-all, set to text as default
if
mime
==
""
{
mime
=
"text/plain"
}
h
.
Set
(
contentTypeHeader
,
mime
)
h
.
Set
(
transferEncodingHeader
,
"chunked"
)
if
r
.
Method
==
"HEAD"
{
// after all the headers.
...
...
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