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-cmds
Commits
7573da7e
Commit
7573da7e
authored
Jul 26, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some commenting
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
13bf48e4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
0 deletions
+9
-0
http/client.go
http/client.go
+7
-0
http/handler.go
http/handler.go
+2
-0
No files found.
http/client.go
View file @
7573da7e
...
...
@@ -242,6 +242,8 @@ func getResponse(httpRes *http.Response, req cmds.Request) (cmds.Response, error
return
res
,
nil
}
// read json objects off of the given stream, and write the objects out to
// the 'out' channel
func
readStreamedJson
(
req
cmds
.
Request
,
httpRes
*
http
.
Response
,
out
chan
<-
interface
{})
{
defer
close
(
out
)
dec
:=
json
.
NewDecoder
(
&
httpResponseReader
{
httpRes
})
...
...
@@ -270,6 +272,8 @@ func readStreamedJson(req cmds.Request, httpRes *http.Response, out chan<- inter
}
}
// decode a value of the given type, if the type is nil, attempt to decode into
// an interface{} anyways
func
decodeTypedVal
(
t
reflect
.
Type
,
dec
*
json
.
Decoder
)
(
interface
{},
error
)
{
var
v
interface
{}
var
err
error
...
...
@@ -283,6 +287,9 @@ func decodeTypedVal(t reflect.Type, dec *json.Decoder) (interface{}, error) {
return
v
,
err
}
// httpResponseReader reads from the response body, and checks for an error
// in the http trailer upon EOF, this error if present is returned instead
// of the EOF.
type
httpResponseReader
struct
{
resp
*
http
.
Response
}
...
...
http/handler.go
View file @
7573da7e
...
...
@@ -193,6 +193,7 @@ func sendResponse(w http.ResponseWriter, req cmds.Request, res cmds.Response) {
mime
=
applicationJson
}
}
if
mime
!=
""
{
h
.
Set
(
contentTypeHeader
,
mime
)
}
...
...
@@ -207,6 +208,7 @@ func sendResponse(w http.ResponseWriter, req cmds.Request, res cmds.Response) {
// Copies from an io.Reader to a http.ResponseWriter.
// Flushes chunks over HTTP stream as they are read (if supported by transport).
func
copyChunks
(
status
int
,
w
http
.
ResponseWriter
,
out
io
.
Reader
)
error
{
// hijack the connection so we can write our own chunked output and trailers
hijacker
,
ok
:=
w
.
(
http
.
Hijacker
)
if
!
ok
{
log
.
Error
(
"Failed to create hijacker! cannot continue!"
)
...
...
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