ijpiantanida / talkback

A simple HTTP proxy that records and playbacks requests
MIT License
284 stars 41 forks source link

Internal 500 error when prettying JSON response #17

Closed onurhb closed 5 years ago

onurhb commented 5 years ago

Given following:

var talkback = require("talkback");

var server = talkback({
  host: "https://jsonplaceholder.typicode.com",
  path: __dirname + "/tapes",
  port: 3002,
  debug: true
});

server.start();

I am getting response 500, when requesting localhost:3002/todos/1 with header: Content-Type: application/json.

Removing this method fixes the problem.

I don't understand why this is necessary.

ijpiantanida commented 5 years ago

Can I ask you how you're making the request?

Normalizing is necessary to compare JSON tapes, since the original body formatting is lost when pretty printing.

onurhb commented 5 years ago

Just curl:

$ curl --header "content-type:application/json" localhost:3002/todos/1 -I

HTTP/1.1 500 Internal Server Error
Date: Fri, 01 Feb 2019 17:19:33 GMT
Connection: keep-alive

or with body:


curl -i -X GET \
  http://localhost:3002/todos/1 \
  -H 'Content-Type: application/json' \
  -d '{
        "Hello": "Hello"
}'

HTTP/1.1 500 Internal Server Error
Date: Fri, 01 Feb 2019 17:35:15 GMT
Connection: keep-alive
Content-Length: 0
ijpiantanida commented 5 years ago

Thanks for the info. The error happened on HEAD requests.

I just published v1.8.1 with a fix.