Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
move request query to http body (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
petar authored Jun 7, 2022
1 parent 3c365e6 commit 0af973b
Show file tree
Hide file tree
Showing 8 changed files with 637 additions and 624 deletions.
1 change: 1 addition & 0 deletions blueprints/base/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var (
IOReadCloser = &cg.GoRef{PkgPath: "io", Name: "ReadCloser"}
IOEOF = &cg.GoRef{PkgPath: "io", Name: "EOF"}
IOErrUnexpectedEOF = &cg.GoRef{PkgPath: "io", Name: "ErrUnexpectedEOF"}
IOUtilReadAll = &cg.GoRef{PkgPath: "io/ioutil", Name: "ReadAll"}
)

const EdelweissServicesPkg = services.PkgPath
Expand Down
3 changes: 0 additions & 3 deletions blueprints/services/dagjson-over-http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,6 @@ func (c *{{.Type}}) {{.AsyncMethodDecl}} {
// encode request in URL
u := *c.endpoint
q := {{.URLValues}}{}
q.Set("q", string(buf))
u.RawQuery = q.Encode()
httpReq, err := {{.HTTPNewRequestWithContext}}(ctx, "POST", u.String(), {{.BytesNewReader}}(buf))
if err != nil {
return nil, err
Expand Down
10 changes: 8 additions & 2 deletions blueprints/services/dagjson-over-http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func (x GoServerImpl) GoDef() cg.Blueprint {
"HTTPResponseWriter": base.HTTPResponseWriter,
"IPLDDecode": base.IPLDDecode,
"DAGJSONDecode": base.DAGJSONDecode,
"IOUtilReadAll": base.IOUtilReadAll,
//
"Interface": x.Ref.Append("_Server"),
"AsyncHandler": x.Ref.Append("_AsyncHandler"),
Expand Down Expand Up @@ -150,8 +151,13 @@ type {{.Interface}} interface {
func {{.AsyncHandler}}(s {{.Interface}}) {{.HTTPHandlerFunc}} {
return func(writer {{.HTTPResponseWriter}}, request *{{.HTTPRequest}}) {
// parse request
msg := request.URL.Query().Get("q")
n, err := {{.IPLDDecode}}([]byte(msg), {{.DAGJSONDecode}})
msg, err := {{.IOUtilReadAll}}(request.Body)
if err != nil {
{{.LoggerVar}}.Errorf("reading request body (%v)", err)
writer.WriteHeader(400)
return
}
n, err := {{.IPLDDecode}}(msg, {{.DAGJSONDecode}})
if err != nil {
{{.LoggerVar}}.Errorf("received request not decodeable (%v)", err)
writer.WriteHeader(400)
Expand Down
Loading

0 comments on commit 0af973b

Please sign in to comment.