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
e57cd9b8
Commit
e57cd9b8
authored
Nov 03, 2014
by
Matt Bell
Committed by
Juan Batiz-Benet
Nov 04, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands/http: Use net/url querystring encoder
parent
33b0990a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
8 deletions
+9
-8
commands/http/client.go
commands/http/client.go
+9
-8
No files found.
commands/http/client.go
View file @
e57cd9b8
...
...
@@ -6,13 +6,14 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"strings"
cmds
"github.com/jbenet/go-ipfs/commands"
)
const
(
ApiUrlFormat
=
"http://%s%s/%s"
ApiUrlFormat
=
"http://%s%s/%s
?%s
"
ApiPath
=
"/api/v0"
// TODO: make configurable
)
...
...
@@ -30,9 +31,6 @@ func NewClient(address string) Client {
}
func
(
c
*
client
)
Send
(
req
cmds
.
Request
)
(
cmds
.
Response
,
error
)
{
path
:=
strings
.
Join
(
req
.
Path
(),
"/"
)
url
:=
fmt
.
Sprintf
(
ApiUrlFormat
,
c
.
serverAddress
,
ApiPath
,
path
)
var
userEncoding
string
if
enc
,
found
:=
req
.
Option
(
cmds
.
EncShort
);
found
{
userEncoding
=
enc
.
(
string
)
...
...
@@ -46,9 +44,9 @@ func (c *client) Send(req cmds.Request) (cmds.Response, error) {
// TODO: handle multiple files with multipart
var
in
io
.
Reader
query
:=
"?"
query
:=
url
.
Values
{}
for
k
,
v
:=
range
req
.
Options
()
{
query
+=
"&"
+
k
+
"="
+
v
.
(
string
)
query
.
Set
(
k
,
v
.
(
string
)
)
}
args
:=
req
.
Arguments
()
...
...
@@ -61,7 +59,7 @@ func (c *client) Send(req cmds.Request) (cmds.Response, error) {
}
if
argDef
.
Type
==
cmds
.
ArgString
{
query
+=
"&arg="
+
arg
.
(
string
)
query
.
Add
(
"arg"
,
arg
.
(
string
)
)
}
else
{
// TODO: multipart
...
...
@@ -72,7 +70,10 @@ func (c *client) Send(req cmds.Request) (cmds.Response, error) {
}
}
httpRes
,
err
:=
http
.
Post
(
url
+
query
,
"application/octet-stream"
,
in
)
path
:=
strings
.
Join
(
req
.
Path
(),
"/"
)
url
:=
fmt
.
Sprintf
(
ApiUrlFormat
,
c
.
serverAddress
,
ApiPath
,
path
,
query
.
Encode
())
httpRes
,
err
:=
http
.
Post
(
url
,
"application/octet-stream"
,
in
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
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