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-unixfs
Commits
c0a9871d
Commit
c0a9871d
authored
Oct 28, 2014
by
Matt Bell
Committed by
Juan Batiz-Benet
Nov 04, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands/http: Made HTTP client unmarshal response values based on the Command#Type
parent
ef290faa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
9 deletions
+19
-9
commands/http/client.go
commands/http/client.go
+19
-9
No files found.
commands/http/client.go
View file @
c0a9871d
package
http
package
http
import
(
import
(
//
"encoding/json"
"encoding/json"
//
"fmt"
"fmt"
"net/http"
"net/http"
"strings"
"strings"
...
@@ -28,6 +28,16 @@ func Send(req cmds.Request) (cmds.Response, error) {
...
@@ -28,6 +28,16 @@ func Send(req cmds.Request) (cmds.Response, error) {
url
:=
"http://"
+
host
+
ApiPath
url
:=
"http://"
+
host
+
ApiPath
url
+=
"/"
+
strings
.
Join
(
req
.
Path
(),
"/"
)
url
+=
"/"
+
strings
.
Join
(
req
.
Path
(),
"/"
)
var
userEncoding
string
if
enc
,
found
:=
req
.
Option
(
cmds
.
EncShort
);
found
{
userEncoding
=
enc
.
(
string
)
req
.
SetOption
(
cmds
.
EncShort
,
cmds
.
JSON
)
}
else
{
enc
,
_
:=
req
.
Option
(
cmds
.
EncLong
)
userEncoding
=
enc
.
(
string
)
req
.
SetOption
(
cmds
.
EncLong
,
cmds
.
JSON
)
}
query
:=
"?"
query
:=
"?"
for
k
,
v
:=
range
req
.
Options
()
{
for
k
,
v
:=
range
req
.
Options
()
{
query
+=
"&"
+
k
+
"="
+
v
.
(
string
)
query
+=
"&"
+
k
+
"="
+
v
.
(
string
)
...
@@ -41,11 +51,7 @@ func Send(req cmds.Request) (cmds.Response, error) {
...
@@ -41,11 +51,7 @@ func Send(req cmds.Request) (cmds.Response, error) {
return
nil
,
err
return
nil
,
err
}
}
// commented out: code to parse HTTP response and turn it into a cmds.Response
// for now, we are simply reading the data as a stream
res
:=
cmds
.
NewResponse
(
req
)
res
:=
cmds
.
NewResponse
(
req
)
res
.
SetValue
(
httpRes
.
Body
)
/*res := cmds.NewResponse(req)
contentType
:=
httpRes
.
Header
[
"Content-Type"
][
0
]
contentType
:=
httpRes
.
Header
[
"Content-Type"
][
0
]
contentType
=
strings
.
Split
(
contentType
,
";"
)[
0
]
contentType
=
strings
.
Split
(
contentType
,
";"
)[
0
]
...
@@ -55,7 +61,6 @@ func Send(req cmds.Request) (cmds.Response, error) {
...
@@ -55,7 +61,6 @@ func Send(req cmds.Request) (cmds.Response, error) {
return
res
,
nil
return
res
,
nil
}
}
// TODO: decode based on `encoding`, using multicodec
dec
:=
json
.
NewDecoder
(
httpRes
.
Body
)
dec
:=
json
.
NewDecoder
(
httpRes
.
Body
)
if
httpRes
.
StatusCode
>=
http
.
StatusBadRequest
{
if
httpRes
.
StatusCode
>=
http
.
StatusBadRequest
{
...
@@ -69,7 +74,7 @@ func Send(req cmds.Request) (cmds.Response, error) {
...
@@ -69,7 +74,7 @@ func Send(req cmds.Request) (cmds.Response, error) {
res
.
SetError
(
e
,
e
.
Code
)
res
.
SetError
(
e
,
e
.
Code
)
}
else
{
}
else
{
v
ar v interface{}
v
:=
req
.
Command
()
.
Type
err
=
dec
.
Decode
(
&
v
)
err
=
dec
.
Decode
(
&
v
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
...
@@ -77,7 +82,12 @@ func Send(req cmds.Request) (cmds.Response, error) {
...
@@ -77,7 +82,12 @@ func Send(req cmds.Request) (cmds.Response, error) {
}
}
res
.
SetValue
(
v
)
res
.
SetValue
(
v
)
}*/
}
if
len
(
userEncoding
)
>
0
{
req
.
SetOption
(
cmds
.
EncShort
,
userEncoding
)
req
.
SetOption
(
cmds
.
EncLong
,
userEncoding
)
}
return
res
,
nil
return
res
,
nil
}
}
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