icyleaf / halite

💎HTTP Requests Client with a chainable REST API, built-in sessions and middlewares.
MIT License
170 stars 13 forks source link

Discuss: Decode json body with JSON logger? #21

Closed icyleaf closed 6 years ago

icyleaf commented 6 years ago

before:

{
  "created_at": "2018-07-03T10:48:04+08:00:00",
  "entry": {
    "request": {
      "body": "name=icyleaf",
      "headers": {
        "User-Agent": "Halite/0.4.0",
        "Accept": "*/*",
        "Connection": "keep-alive",
        "Content-Type": "application/x-www-form-urlencoded"
      },
      "method": "POST",
      "url": "https://httpbin.org/post",
      "timestamp": "2018-07-03T10:48:05+08:00:00"
    },
    "response": {
      "body": "{\"args\":{},\"data\":\"\",\"files\":{},\"form\":{\"name\":\"icyleaf\"},\"headers\":{\"Accept\":\"*/*\",\"Accept-Encoding\":\"gzip, deflate\",\"Connection\":\"close\",\"Content-Length\":\"12\",\"Content-Type\":\"application/x-www-form-urlencoded\",\"Host\":\"httpbin.org\",\"User-Agent\":\"Halite/0.4.0\"},\"json\":null,\"origin\":\"60.206.194.34\",\"url\":\"https://httpbin.org/post\"}\n",
      "header": {
        "Connection": "keep-alive",
        "Server": "gunicorn/19.8.1",
        "Date": "Tue, 03 Jul 2018 02:48:05 GMT",
        "Content-Type": "application/json",
        "Content-Length": "333",
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": "true",
        "Via": "1.1 vegur"
      },
      "status_code": 200,
      "http_version": "HTTP/1.1",
      "timestamp": "2018-07-03T10:48:05+08:00:00"
    }
  }
}

after:

{
  "created_at": "2018-07-03T10:48:04+08:00:00",
  "entry": {
    "request": {
      "body": "name=icyleaf",
      "headers": {
        "User-Agent": "Halite/0.4.0",
        "Accept": "*/*",
        "Connection": "keep-alive",
        "Content-Type": "application/x-www-form-urlencoded"
      },
      "method": "POST",
      "url": "https://httpbin.org/post",
      "timestamp": "2018-07-03T10:48:05+08:00:00"
    },
    "response": {
      "body": {
        "args": {},
        "data": "",
        "files": {},
        "form": {
          "name": "icyleaf"
        },
        "headers": {
          "Accept": "*/*",
          "Accept-Encoding": "gzip, deflate",
          "Connection": "close",
          "Content-Length": "12",
          "Content-Type": "application/x-www-form-urlencoded",
          "Host": "httpbin.org",
          "User-Agent": "Halite/0.4.0"
        },
        "json": null,
        "origin": "60.206.194.34",
        "url": "https://httpbin.org/post"
      },
      "header": {
        "Connection": "keep-alive",
        "Server": "gunicorn/19.8.1",
        "Date": "Tue, 03 Jul 2018 02:48:05 GMT",
        "Content-Type": "application/json",
        "Content-Length": "333",
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": "true",
        "Via": "1.1 vegur"
      },
      "status_code": 200,
      "http_version": "HTTP/1.1",
      "timestamp": "2018-07-03T10:48:05+08:00:00"
    }
  }
}
icyleaf commented 6 years ago

I thinks it's better to keep the raw string.