Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect debug log for request body of type slice #197

Closed
jdeflander opened this issue Nov 9, 2018 · 4 comments · Fixed by #198
Closed

Incorrect debug log for request body of type slice #197

jdeflander opened this issue Nov 9, 2018 · 4 comments · Fixed by #198
Assignees
Labels

Comments

@jdeflander
Copy link
Contributor

Given the following program:

package main

import "gopkg.in/resty.v1"

func main() {
	body := []string{"foo", "bar", "baz"}

	resty.SetDebug(true)
	resty.R().SetBody(body).Post("https://postman-echo.com/post")
	resty.SetDebug(false)
}

I would expect the following output:

RESTY 2018/11/09 13:48:24 
---------------------- REQUEST LOG -----------------------
POST  /post  HTTP/1.1
HOST   : postman-echo.com
HEADERS:
             Content-Type: application/json; charset=utf-8
               User-Agent: go-resty/1.9.1 (https://github.com/go-resty/resty)
BODY   :
[
   "foo",
   "bar",
   "baz"
]
----------------------------------------------------------
RESTY 2018/11/09 13:48:25 
---------------------- RESPONSE LOG -----------------------
STATUS 		: 200 OK
RECEIVED AT	: 2018-11-09T13:48:25.615705+01:00
RESPONSE TIME	: 666.183314ms
HEADERS:
               Connection: keep-alive
             Content-Type: application/json; charset=utf-8
                     Date: Fri, 09 Nov 2018 12:48:25 GMT
                     Etag: W/"179-Bh4U+8Ua0Ou3igttD6tq0W3jbco"
                   Server: nginx
               Set-Cookie: sails.sid=s%3AkG0u-WtZBNxMcyxM9AeB72VClWUn5c3Q.x4F%2FGyIxEwmOauqPvDxfpPKECn8axHH3uoukxjjfr7U; Path=/; HttpOnly
                     Vary: Accept-Encoding
BODY   :
{
   "args": {},
   "data": [
      "foo",
      "bar",
      "baz"
   ],
   "files": {},
   "form": {},
   "headers": {
      "x-forwarded-proto": "https",
      "host": "postman-echo.com",
      "content-length": "19",
      "accept-encoding": "gzip",
      "content-type": "application/json; charset=utf-8",
      "user-agent": "go-resty/1.9.1 (https://github.com/go-resty/resty)",
      "x-forwarded-port": "443"
   },
   "json": [
      "foo",
      "bar",
      "baz"
   ],
   "url": "https://postman-echo.com/post"
}
----------------------------------------------------------

But instead I got:

RESTY 2018/11/09 13:43:53 
---------------------- REQUEST LOG -----------------------
POST  /post  HTTP/1.1
HOST   : postman-echo.com
HEADERS:
             Content-Type: application/json; charset=utf-8
               User-Agent: go-resty/1.9.1 (https://github.com/go-resty/resty)
BODY   :
***** NO CONTENT *****
----------------------------------------------------------
RESTY 2018/11/09 13:43:53 
---------------------- RESPONSE LOG -----------------------
STATUS 		: 200 OK
RECEIVED AT	: 2018-11-09T13:43:53.653759+01:00
RESPONSE TIME	: 652.783471ms
HEADERS:
               Connection: keep-alive
             Content-Type: application/json; charset=utf-8
                     Date: Fri, 09 Nov 2018 12:43:53 GMT
                     Etag: W/"179-Bh4U+8Ua0Ou3igttD6tq0W3jbco"
                   Server: nginx
               Set-Cookie: sails.sid=s%3A9xXAEl5B6Yr984iRM5Ev7luiYR_8taU1.nFM5cHxR9x7gIS3PWJedTOhl0zqG5o%2FhKtyJWvXGsnQ; Path=/; HttpOnly
                     Vary: Accept-Encoding
BODY   :
{
   "args": {},
   "data": [
      "foo",
      "bar",
      "baz"
   ],
   "files": {},
   "form": {},
   "headers": {
      "x-forwarded-proto": "https",
      "host": "postman-echo.com",
      "content-length": "19",
      "accept-encoding": "gzip",
      "content-type": "application/json; charset=utf-8",
      "user-agent": "go-resty/1.9.1 (https://github.com/go-resty/resty)",
      "x-forwarded-port": "443"
   },
   "json": [
      "foo",
      "bar",
      "baz"
   ],
   "url": "https://postman-echo.com/post"
}
----------------------------------------------------------

Clearly, the body has been posted correctly, but the debug log ignores it completely.

@jeevatkm jeevatkm self-assigned this Nov 9, 2018
@jeevatkm
Copy link
Member

jeevatkm commented Nov 9, 2018

@jdeflander Thanks for reporting it. I have did few improvements in the latest release. Could you please try latest v1.10.1 and let me know whether you still reproduce this debug log issue?

@jdeflander
Copy link
Contributor Author

Issue is still present in the latest version. I think the problem is that slices are not marked as valid for JSON marshalling.

@jeevatkm
Copy link
Member

jeevatkm commented Nov 9, 2018

@jdeflander Thanks for verifying it. I have just looked at your PR. I will merge and make release of v1.10.2

@jeevatkm
Copy link
Member

jeevatkm commented Nov 9, 2018

v1.10.2 released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants