{"action":"created","comment":{"url":"https://api.github.com/repos/JetBrains/ktor/pulls/comments/37791515","id":37791515,"diff_hunk":"@@ -0,0 +1,150 @@\n+package org.jetbrains.ktor.http.cookies\n+\n+import org.jetbrains.ktor.application.*\n+import org.jetbrains.ktor.http.*\n+import java.net.*\n+import java.time.*\n+import java.time.temporal.*\n+import java.util.*\n+\n+public enum class CookieEncoding {\n+    RAW, DQUOTES, URI_ENCODING, BASE64_ENCODING\n+}\n+\n+public open class RequestCookies(val request: ApplicationRequest) {\n+    private val defaultDecoded: Map<String, String> by lazy { decode(CookieEncoding.URI_ENCODING) }\n+\n+    public fun get(name: String): String? = defaultDecoded[name]\n+    public fun decode(encoding: CookieEncoding): Map<String, String> = request.attributes.getOrPut(CookiesKey(encoding)) {\n+        parsedRawCookies.mapValues { decodeCookieValue(it.value, encoding) }\n+    }\n+\n+    public open val parsedRawCookies: Map<String, String> by lazy {\n+        request.header(\"Cookie\")?.let { parseClientCookiesHeader(it) } ?: emptyMap()\n+    }\n+}\n+\n+public fun parseClientCookiesHeader(cookiesHeader: String): Map<String, String> =\n+        cookiesHeader.trimStart().split(\"[;,]\\\\s*\".toRegex())\n+                .filter { !it.startsWith(\"$\") && '=' in it }\n+                .map { it.split(\"=\") }\n+                .toMap({ it[0].trim() }, { it[1] })\n+\n+public fun renderSetCookieHeader(name: String,\n+                                 value: String,\n+                                 encoding: CookieEncoding = CookieEncoding.URI_ENCODING,\n+                                 maxAge: Int = 0,\n+                                 expires: Temporal? = null,\n+                                 domain: String = \"\",\n+                                 path: String = \"\",\n+                                 secure: Boolean = false,\n+                                 httpOnly: Boolean = false,\n+                                 extensions: Map<String, String?> = emptyMap()): String =\n+        (listOf(\n+                cookiePart(name.assertCookieName(), value, encoding),\n+                cookiePartUnencoded(\"Max-Age\", if (maxAge > 0) maxAge else null),\n+                cookiePartUnencoded(\"Expires\", expires?.toHttpDateString()),\n+                cookiePart(\"Domain\", domain.nullIfEmpty(), CookieEncoding.RAW),\n+                cookiePart(\"Path\", path.nullIfEmpty(), CookieEncoding.RAW),\n+\n+                cookiePartFlag(\"Secure\", secure),\n+                cookiePartFlag(\"HttpOnly\", httpOnly)\n+        ) + extensions.map {\n+            cookiePartExt(it.key.assertCookieName(), it.value, encoding)\n+        }).filter { it.isNotEmpty() }\n+                .joinToString(\"; \")\n+\n+\n+public fun ApplicationResponse.setCookie(name: String,","path":"ktor-core/src/org/jetbrains/ktor/http/Cookies.kt","position":58,"original_position":58,"commit_id":"001dcf0200e02f370bbdeb2965c9ee112dbcd098","original_commit_id":"001dcf0200e02f370bbdeb2965c9ee112dbcd098","user":{"login":"orangy","id":616841,"avatar_url":"https://avatars.githubusercontent.com/u/616841?v=3","gravatar_id":"","url":"https://api.github.com/users/orangy","html_url":"https://github.com/orangy","followers_url":"https://api.github.com/users/orangy/followers","following_url":"https://api.github.com/users/orangy/following{/other_user}","gists_url":"https://api.github.com/users/orangy/gists{/gist_id}","starred_url":"https://api.github.com/users/orangy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orangy/subscriptions","organizations_url":"https://api.github.com/users/orangy/orgs","repos_url":"https://api.github.com/users/orangy/repos","events_url":"https://api.github.com/users/orangy/events{/privacy}","received_events_url":"https://api.github.com/users/orangy/received_events","type":"User","site_admin":false},"body":"Interceptors should be able to examine cookies set by handlers and other interceptors. With this solution they will have to intercept headers and decode them back.","created_at":"2015-08-24T19:10:59Z","updated_at":"2015-08-24T19:10:59Z","html_url":"https://github.com/JetBrains/ktor/pull/2#discussion_r37791515","pull_request_url":"https://api.github.com/repos/JetBrains/ktor/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/JetBrains/ktor/pulls/comments/37791515"},"html":{"href":"https://github.com/JetBrains/ktor/pull/2#discussion_r37791515"},"pull_request":{"href":"https://api.github.com/repos/JetBrains/ktor/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/JetBrains/ktor/pulls/2","id":43163029,"html_url":"https://github.com/JetBrains/ktor/pull/2","diff_url":"https://github.com/JetBrains/ktor/pull/2.diff","patch_url":"https://github.com/JetBrains/ktor/pull/2.patch","issue_url":"https://api.github.com/repos/JetBrains/ktor/issues/2","number":2,"state":"open","locked":false,"title":"Cookies support","user":{"login":"cy6erGn0m","id":762598,"avatar_url":"https://avatars.githubusercontent.com/u/762598?v=3","gravatar_id":"","url":"https://api.github.com/users/cy6erGn0m","html_url":"https://github.com/cy6erGn0m","followers_url":"https://api.github.com/users/cy6erGn0m/followers","following_url":"https://api.github.com/users/cy6erGn0m/following{/other_user}","gists_url":"https://api.github.com/users/cy6erGn0m/gists{/gist_id}","starred_url":"https://api.github.com/users/cy6erGn0m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cy6erGn0m/subscriptions","organizations_url":"https://api.github.com/users/cy6erGn0m/orgs","repos_url":"https://api.github.com/users/cy6erGn0m/repos","events_url":"https://api.github.com/users/cy6erGn0m/events{/privacy}","received_events_url":"https://api.github.com/users/cy6erGn0m/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-08-24T11:04:26Z","updated_at":"2015-08-24T19:10:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8d1baf5faa992eca64deb04b0bab046f2a4ae3db","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/JetBrains/ktor/pulls/2/commits","review_comments_url":"https://api.github.com/repos/JetBrains/ktor/pulls/2/comments","review_comment_url":"https://api.github.com/repos/JetBrains/ktor/pulls/comments{/number}","comments_url":"https://api.github.com/repos/JetBrains/ktor/issues/2/comments","statuses_url":"https://api.github.com/repos/JetBrains/ktor/statuses/001dcf0200e02f370bbdeb2965c9ee112dbcd098","head":{"label":"cy6erGn0m:cookies","ref":"cookies","sha":"001dcf0200e02f370bbdeb2965c9ee112dbcd098","user":{"login":"cy6erGn0m","id":762598,"avatar_url":"https://avatars.githubusercontent.com/u/762598?v=3","gravatar_id":"","url":"https://api.github.com/users/cy6erGn0m","html_url":"https://github.com/cy6erGn0m","followers_url":"https://api.github.com/users/cy6erGn0m/followers","following_url":"https://api.github.com/users/cy6erGn0m/following{/other_user}","gists_url":"https://api.github.com/users/cy6erGn0m/gists{/gist_id}","starred_url":"https://api.github.com/users/cy6erGn0m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cy6erGn0m/subscriptions","organizations_url":"https://api.github.com/users/cy6erGn0m/orgs","repos_url":"https://api.github.com/users/cy6erGn0m/repos","events_url":"https://api.github.com/users/cy6erGn0m/events{/privacy}","received_events_url":"https://api.github.com/users/cy6erGn0m/received_events","type":"User","site_admin":false},"repo":{"id":40906748,"name":"ktor","full_name":"cy6erGn0m/ktor","owner":{"login":"cy6erGn0m","id":762598,"avatar_url":"https://avatars.githubusercontent.com/u/762598?v=3","gravatar_id":"","url":"https://api.github.com/users/cy6erGn0m","html_url":"https://github.com/cy6erGn0m","followers_url":"https://api.github.com/users/cy6erGn0m/followers","following_url":"https://api.github.com/users/cy6erGn0m/following{/other_user}","gists_url":"https://api.github.com/users/cy6erGn0m/gists{/gist_id}","starred_url":"https://api.github.com/users/cy6erGn0m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cy6erGn0m/subscriptions","organizations_url":"https://api.github.com/users/cy6erGn0m/orgs","repos_url":"https://api.github.com/users/cy6erGn0m/repos","events_url":"https://api.github.com/users/cy6erGn0m/events{/privacy}","received_events_url":"https://api.github.com/users/cy6erGn0m/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cy6erGn0m/ktor","description":"Web backend framework for Kotlin","fork":true,"url":"https://api.github.com/repos/cy6erGn0m/ktor","forks_url":"https://api.github.com/repos/cy6erGn0m/ktor/forks","keys_url":"https://api.github.com/repos/cy6erGn0m/ktor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cy6erGn0m/ktor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cy6erGn0m/ktor/teams","hooks_url":"https://api.github.com/repos/cy6erGn0m/ktor/hooks","issue_events_url":"https://api.github.com/repos/cy6erGn0m/ktor/issues/events{/number}","events_url":"https://api.github.com/repos/cy6erGn0m/ktor/events","assignees_url":"https://api.github.com/repos/cy6erGn0m/ktor/assignees{/user}","branches_url":"https://api.github.com/repos/cy6erGn0m/ktor/branches{/branch}","tags_url":"https://api.github.com/repos/cy6erGn0m/ktor/tags","blobs_url":"https://api.github.com/repos/cy6erGn0m/ktor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cy6erGn0m/ktor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cy6erGn0m/ktor/git/refs{/sha}","trees_url":"https://api.github.com/repos/cy6erGn0m/ktor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cy6erGn0m/ktor/statuses/{sha}","languages_url":"https://api.github.com/repos/cy6erGn0m/ktor/languages","stargazers_url":"https://api.github.com/repos/cy6erGn0m/ktor/stargazers","contributors_url":"https://api.github.com/repos/cy6erGn0m/ktor/contributors","subscribers_url":"https://api.github.com/repos/cy6erGn0m/ktor/subscribers","subscription_url":"https://api.github.com/repos/cy6erGn0m/ktor/subscription","commits_url":"https://api.github.com/repos/cy6erGn0m/ktor/commits{/sha}","git_commits_url":"https://api.github.com/repos/cy6erGn0m/ktor/git/commits{/sha}","comments_url":"https://api.github.com/repos/cy6erGn0m/ktor/comments{/number}","issue_comment_url":"https://api.github.com/repos/cy6erGn0m/ktor/issues/comments{/number}","contents_url":"https://api.github.com/repos/cy6erGn0m/ktor/contents/{+path}","compare_url":"https://api.github.com/repos/cy6erGn0m/ktor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cy6erGn0m/ktor/merges","archive_url":"https://api.github.com/repos/cy6erGn0m/ktor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cy6erGn0m/ktor/downloads","issues_url":"https://api.github.com/repos/cy6erGn0m/ktor/issues{/number}","pulls_url":"https://api.github.com/repos/cy6erGn0m/ktor/pulls{/number}","milestones_url":"https://api.github.com/repos/cy6erGn0m/ktor/milestones{/number}","notifications_url":"https://api.github.com/repos/cy6erGn0m/ktor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cy6erGn0m/ktor/labels{/name}","releases_url":"https://api.github.com/repos/cy6erGn0m/ktor/releases{/id}","created_at":"2015-08-17T15:40:03Z","updated_at":"2015-08-17T15:40:04Z","pushed_at":"2015-08-24T18:25:36Z","git_url":"git://github.com/cy6erGn0m/ktor.git","ssh_url":"git@github.com:cy6erGn0m/ktor.git","clone_url":"https://github.com/cy6erGn0m/ktor.git","svn_url":"https://github.com/cy6erGn0m/ktor","homepage":"","size":483,"stargazers_count":0,"watchers_count":0,"language":"Kotlin","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"JetBrains:master","ref":"master","sha":"041000d575f4659cbac18f594f55d0b6125ac430","user":{"login":"JetBrains","id":878437,"avatar_url":"https://avatars.githubusercontent.com/u/878437?v=3","gravatar_id":"","url":"https://api.github.com/users/JetBrains","html_url":"https://github.com/JetBrains","followers_url":"https://api.github.com/users/JetBrains/followers","following_url":"https://api.github.com/users/JetBrains/following{/other_user}","gists_url":"https://api.github.com/users/JetBrains/gists{/gist_id}","starred_url":"https://api.github.com/users/JetBrains/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JetBrains/subscriptions","organizations_url":"https://api.github.com/users/JetBrains/orgs","repos_url":"https://api.github.com/users/JetBrains/repos","events_url":"https://api.github.com/users/JetBrains/events{/privacy}","received_events_url":"https://api.github.com/users/JetBrains/received_events","type":"Organization","site_admin":false},"repo":{"id":40136600,"name":"ktor","full_name":"JetBrains/ktor","owner":{"login":"JetBrains","id":878437,"avatar_url":"https://avatars.githubusercontent.com/u/878437?v=3","gravatar_id":"","url":"https://api.github.com/users/JetBrains","html_url":"https://github.com/JetBrains","followers_url":"https://api.github.com/users/JetBrains/followers","following_url":"https://api.github.com/users/JetBrains/following{/other_user}","gists_url":"https://api.github.com/users/JetBrains/gists{/gist_id}","starred_url":"https://api.github.com/users/JetBrains/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JetBrains/subscriptions","organizations_url":"https://api.github.com/users/JetBrains/orgs","repos_url":"https://api.github.com/users/JetBrains/repos","events_url":"https://api.github.com/users/JetBrains/events{/privacy}","received_events_url":"https://api.github.com/users/JetBrains/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/JetBrains/ktor","description":"Web backend framework for Kotlin","fork":false,"url":"https://api.github.com/repos/JetBrains/ktor","forks_url":"https://api.github.com/repos/JetBrains/ktor/forks","keys_url":"https://api.github.com/repos/JetBrains/ktor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JetBrains/ktor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JetBrains/ktor/teams","hooks_url":"https://api.github.com/repos/JetBrains/ktor/hooks","issue_events_url":"https://api.github.com/repos/JetBrains/ktor/issues/events{/number}","events_url":"https://api.github.com/repos/JetBrains/ktor/events","assignees_url":"https://api.github.com/repos/JetBrains/ktor/assignees{/user}","branches_url":"https://api.github.com/repos/JetBrains/ktor/branches{/branch}","tags_url":"https://api.github.com/repos/JetBrains/ktor/tags","blobs_url":"https://api.github.com/repos/JetBrains/ktor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JetBrains/ktor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JetBrains/ktor/git/refs{/sha}","trees_url":"https://api.github.com/repos/JetBrains/ktor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JetBrains/ktor/statuses/{sha}","languages_url":"https://api.github.com/repos/JetBrains/ktor/languages","stargazers_url":"https://api.github.com/repos/JetBrains/ktor/stargazers","contributors_url":"https://api.github.com/repos/JetBrains/ktor/contributors","subscribers_url":"https://api.github.com/repos/JetBrains/ktor/subscribers","subscription_url":"https://api.github.com/repos/JetBrains/ktor/subscription","commits_url":"https://api.github.com/repos/JetBrains/ktor/commits{/sha}","git_commits_url":"https://api.github.com/repos/JetBrains/ktor/git/commits{/sha}","comments_url":"https://api.github.com/repos/JetBrains/ktor/comments{/number}","issue_comment_url":"https://api.github.com/repos/JetBrains/ktor/issues/comments{/number}","contents_url":"https://api.github.com/repos/JetBrains/ktor/contents/{+path}","compare_url":"https://api.github.com/repos/JetBrains/ktor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JetBrains/ktor/merges","archive_url":"https://api.github.com/repos/JetBrains/ktor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JetBrains/ktor/downloads","issues_url":"https://api.github.com/repos/JetBrains/ktor/issues{/number}","pulls_url":"https://api.github.com/repos/JetBrains/ktor/pulls{/number}","milestones_url":"https://api.github.com/repos/JetBrains/ktor/milestones{/number}","notifications_url":"https://api.github.com/repos/JetBrains/ktor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JetBrains/ktor/labels{/name}","releases_url":"https://api.github.com/repos/JetBrains/ktor/releases{/id}","created_at":"2015-08-03T16:49:36Z","updated_at":"2015-08-22T13:48:42Z","pushed_at":"2015-08-24T19:07:17Z","git_url":"git://github.com/JetBrains/ktor.git","ssh_url":"git@github.com:JetBrains/ktor.git","clone_url":"https://github.com/JetBrains/ktor.git","svn_url":"https://github.com/JetBrains/ktor","homepage":"","size":520,"stargazers_count":2,"watchers_count":2,"language":"Kotlin","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":1,"forks":4,"open_issues":1,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/JetBrains/ktor/pulls/2"},"html":{"href":"https://github.com/JetBrains/ktor/pull/2"},"issue":{"href":"https://api.github.com/repos/JetBrains/ktor/issues/2"},"comments":{"href":"https://api.github.com/repos/JetBrains/ktor/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/JetBrains/ktor/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/JetBrains/ktor/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/JetBrains/ktor/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/JetBrains/ktor/statuses/001dcf0200e02f370bbdeb2965c9ee112dbcd098"}}}}