{"action":"created","issue":{"url":"https://api.github.com/repos/unexpectedjs/unexpected-mitm/issues/1","labels_url":"https://api.github.com/repos/unexpectedjs/unexpected-mitm/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/unexpectedjs/unexpected-mitm/issues/1/comments","events_url":"https://api.github.com/repos/unexpectedjs/unexpected-mitm/issues/1/events","html_url":"https://github.com/unexpectedjs/unexpected-mitm/pull/1","id":85934166,"number":1,"title":"Dynamic response","user":{"login":"alexjeffburke","id":721814,"avatar_url":"https://avatars.githubusercontent.com/u/721814?v=3","gravatar_id":"","url":"https://api.github.com/users/alexjeffburke","html_url":"https://github.com/alexjeffburke","followers_url":"https://api.github.com/users/alexjeffburke/followers","following_url":"https://api.github.com/users/alexjeffburke/following{/other_user}","gists_url":"https://api.github.com/users/alexjeffburke/gists{/gist_id}","starred_url":"https://api.github.com/users/alexjeffburke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexjeffburke/subscriptions","organizations_url":"https://api.github.com/users/alexjeffburke/orgs","repos_url":"https://api.github.com/users/alexjeffburke/repos","events_url":"https://api.github.com/users/alexjeffburke/events{/privacy}","received_events_url":"https://api.github.com/users/alexjeffburke/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-06-07T20:03:37Z","updated_at":"2015-06-16T21:00:24Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/unexpectedjs/unexpected-mitm/pulls/1","html_url":"https://github.com/unexpectedjs/unexpected-mitm/pull/1","diff_url":"https://github.com/unexpectedjs/unexpected-mitm/pull/1.diff","patch_url":"https://github.com/unexpectedjs/unexpected-mitm/pull/1.patch"},"body":"Can I get an initial review for this?\r\n\r\nThis pull request makes it it possible to supply a function as the response property which will generate a dynamic response based upon the request object.\r\n\r\nThis version allows an generating the response to be an asynchronous operation. It comes with tests of the success and failure cases."},"comment":{"url":"https://api.github.com/repos/unexpectedjs/unexpected-mitm/issues/comments/112568678","html_url":"https://github.com/unexpectedjs/unexpected-mitm/pull/1#issuecomment-112568678","issue_url":"https://api.github.com/repos/unexpectedjs/unexpected-mitm/issues/1","id":112568678,"user":{"login":"papandreou","id":373545,"avatar_url":"https://avatars.githubusercontent.com/u/373545?v=3","gravatar_id":"","url":"https://api.github.com/users/papandreou","html_url":"https://github.com/papandreou","followers_url":"https://api.github.com/users/papandreou/followers","following_url":"https://api.github.com/users/papandreou/following{/other_user}","gists_url":"https://api.github.com/users/papandreou/gists{/gist_id}","starred_url":"https://api.github.com/users/papandreou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/papandreou/subscriptions","organizations_url":"https://api.github.com/users/papandreou/orgs","repos_url":"https://api.github.com/users/papandreou/repos","events_url":"https://api.github.com/users/papandreou/events{/privacy}","received_events_url":"https://api.github.com/users/papandreou/received_events","type":"User","site_admin":false},"created_at":"2015-06-16T21:00:24Z","updated_at":"2015-06-16T21:00:24Z","body":"This looks really great! I'll be happy to merge it in its current state.\r\n\r\nI have a couple of follow-up feature requests:\r\n\r\n### Capturing the low-level response ###\r\n\r\nI recently changed unexpected-express to capture the response generated by the express app by looking at what's written to the socket rather than into the `http.ServerResponse` instance: https://github.com/unexpectedjs/unexpected-express/blob/d82330e5ab5e4a3dee00a694583f5e95e47a26ea/lib/unexpectedExpress.js#L269-L274 ... and use messy's low-level parser to parse both the headers and the body: https://github.com/unexpectedjs/unexpected-express/blob/d82330e5ab5e4a3dee00a694583f5e95e47a26ea/lib/unexpectedExpress.js#L344-L346\r\n\r\nThat enables us to assert things about the chunked encoding. The original usecase was a one we ran into at the ol' company where an express handler had to write bogus into the socket in order to force a browser downloading a big file to consider the download to have failed. Once a certain amount of data had been streamed, Chrome simply refused to realize that the download had failed unless we did that, otherwise it would leave a truncated file on disc and allow the user to open it. To test this piece of code we needed to assert that the raw response body (`Transfer-Encoding: chunked`) ended with `XXX`.\r\n\r\nAlso, node.js (0.12+ I think) plays some tricks when you provide non-ASCII chars in a header. If the chars can be represented in iso-8859-1, it will output them like that. This happens right before the bytes are written into the socket, so you need to listen the raw socket output in order to know what actually happened, neither `res._header` nor `res.headers` will reflect that.\r\n\r\n### Longer conversations with a dynamic response ###\r\n\r\nCould there be some kind of shorthand for saying that a series of requests is to be processed by the same app?"}}