{"action":"created","issue":{"url":"https://api.github.com/repos/ktorio/ktor/issues/505","repository_url":"https://api.github.com/repos/ktorio/ktor","labels_url":"https://api.github.com/repos/ktorio/ktor/issues/505/labels{/name}","comments_url":"https://api.github.com/repos/ktorio/ktor/issues/505/comments","events_url":"https://api.github.com/repos/ktorio/ktor/issues/505/events","html_url":"https://github.com/ktorio/ktor/issues/505","id":346946436,"node_id":"MDU6SXNzdWUzNDY5NDY0MzY=","number":505,"title":"Question: Log first X bytes of a request.","user":{"login":"bhandfast","id":1254624,"node_id":"MDQ6VXNlcjEyNTQ2MjQ=","avatar_url":"https://avatars2.githubusercontent.com/u/1254624?v=4","gravatar_id":"","url":"https://api.github.com/users/bhandfast","html_url":"https://github.com/bhandfast","followers_url":"https://api.github.com/users/bhandfast/followers","following_url":"https://api.github.com/users/bhandfast/following{/other_user}","gists_url":"https://api.github.com/users/bhandfast/gists{/gist_id}","starred_url":"https://api.github.com/users/bhandfast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bhandfast/subscriptions","organizations_url":"https://api.github.com/users/bhandfast/orgs","repos_url":"https://api.github.com/users/bhandfast/repos","events_url":"https://api.github.com/users/bhandfast/events{/privacy}","received_events_url":"https://api.github.com/users/bhandfast/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-02T10:09:51Z","updated_at":"2018-08-08T06:29:54Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\n\r\nFor debug purposes I'm trying to log the first X bytes of a POST request on the server. Is there a way to do this with an interceptor? I've tried the following naive way of logging it (which doesn't work):\r\n\r\n```kotlin\r\nsuspend private fun intercept(pipelineContext: PipelineContext<Unit, ApplicationCall>) {\r\n      logger.info(\"Intercept\");\r\n      val stream = pipelineContext.context.request.call.receiveStream()\r\n      stream.mark(1024)\r\n\r\n      val bytes = stream.readBytes(1024)\r\n      stream.reset()\r\n}\r\n```\r\n\r\nChannels seem to be the underlying infrastructure for the stream, and that doesn't support mark/reset as far as I know. And they cannot be replaced as I understand it."},"comment":{"url":"https://api.github.com/repos/ktorio/ktor/issues/comments/411300540","html_url":"https://github.com/ktorio/ktor/issues/505#issuecomment-411300540","issue_url":"https://api.github.com/repos/ktorio/ktor/issues/505","id":411300540,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMTMwMDU0MA==","user":{"login":"e5l","id":4290035,"node_id":"MDQ6VXNlcjQyOTAwMzU=","avatar_url":"https://avatars1.githubusercontent.com/u/4290035?v=4","gravatar_id":"","url":"https://api.github.com/users/e5l","html_url":"https://github.com/e5l","followers_url":"https://api.github.com/users/e5l/followers","following_url":"https://api.github.com/users/e5l/following{/other_user}","gists_url":"https://api.github.com/users/e5l/gists{/gist_id}","starred_url":"https://api.github.com/users/e5l/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/e5l/subscriptions","organizations_url":"https://api.github.com/users/e5l/orgs","repos_url":"https://api.github.com/users/e5l/repos","events_url":"https://api.github.com/users/e5l/events{/privacy}","received_events_url":"https://api.github.com/users/e5l/received_events","type":"User","site_admin":false},"created_at":"2018-08-08T06:29:54Z","updated_at":"2018-08-08T06:29:54Z","author_association":"CONTRIBUTOR","body":"Hi, @bhandfast. Thanks to notice.\r\n\r\nYou could insert the interceptor that wraps channel in following way:\r\n```\r\nfun ByteReadChannel.logFirst(count: Int): ByteReadChannel = writer(DefaultDispatcher) {\r\n    val source = this@logFirst\r\n    \r\n    val head = ByteArray(count)\r\n    source.readFully(head)\r\n    \r\n    // perform logging of head here\r\n    \r\n    channel.writeFully(head)\r\n    source.joinTo(channel) // or source.copyTo(channel)\r\n}.channel\r\n```\r\n\r\n"}}
{"actor":{"display_login":"e5l"}}