{"action":"created","comment":{"url":"https://api.github.com/repos/scalatra/scalatra/pulls/comments/197730126","pull_request_review_id":131528368,"id":197730126,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5NzczMDEyNg==","diff_hunk":"@@ -1,101 +1,92 @@\n package org.scalatra.util\n \n-import java.io.{ File, InputStream }\n-import java.net.{ URI, URL }\n-\n-import eu.medsea.mimeutil.{ MimeType, MimeUtil2 }\n-import eu.medsea.util.EncodingGuesser\n-import org.slf4j.LoggerFactory\n-\n-import scala.collection.JavaConverters._\n-import scala.util.control.Exception._\n+import java.io.{ File, InputStream, ByteArrayInputStream }\n+import java.net.{ URI, URLConnection }\n \n object Mimes {\n-\n   val DefaultMime = \"application/octet-stream\"\n-  /**\n-   * Sets supported encodings for the mime-util library if they have not been\n-   * set. Since the supported encodings is stored as a static Set we\n-   * synchronize access.\n-   */\n-  private def registerEncodingsIfNotSet(): Unit = {\n-    synchronized {\n-      if (EncodingGuesser.getSupportedEncodings.isEmpty) {\n-        val enc = Set(\"UTF-8\", \"ISO-8859-1\", \"windows-1252\", \"MacRoman\", EncodingGuesser.getDefaultEncoding)\n-        EncodingGuesser.setSupportedEncodings(enc.asJava)\n-      }\n-    }\n-  }\n-  registerEncodingsIfNotSet\n }\n \n /**\n- * A utility to help with mime type detection for a given file path or url\n+ * A utility to help with mime type detection for a given file path or url.\n  */\n+\n trait Mimes {\n \n   import org.scalatra.util.Mimes._\n \n-  @transient private[this] val internalLogger = LoggerFactory.getLogger(getClass)\n-\n-  protected[this] def mimeUtil: MimeUtil2 = new MimeUtil2()\n-  quiet { mimeUtil.registerMimeDetector(\"eu.medsea.mimeutil.detector.MagicMimeMimeDetector\") }\n-  quiet { mimeUtil.registerMimeDetector(\"eu.medsea.mimeutil.detector.ExtensionMimeDetector\") }\n-\n+  /**\n+   * Detects the mime type of a given Byte array.\n+   *\n+   * When inappropriate MIME Type can not be inferred,\n+   * \"text/pain\" is returned.\n+   *\n+   * @param content The Byte array for which to detect the mime type\n+   * @param fallback A fallback value in case no mime type can be found\n+   */\n   def bytesMime(content: Array[Byte], fallback: String = DefaultMime): String = {\n-    detectMime(fallback) {\n-      MimeUtil2.getMostSpecificMimeType(mimeUtil.getMimeTypes(content, new MimeType(fallback))).toString\n+    // for backward compatibility...even when it is empty, \"text/plain\" may be good.\n+    if (content.isEmpty == true) {\n+      return fallback\n     }\n+\n+    val is = new ByteArrayInputStream(content)\n+    val mimeType = URLConnection.guessContentTypeFromStream(is)\n+\n+    if (mimeType != null) mimeType else \"text/plain\"","path":"core/src/main/scala/org/scalatra/util/Mimes.scala","position":69,"original_position":69,"commit_id":"e4ae79604d252b040129ce7056375dcaaa60030b","original_commit_id":"e4ae79604d252b040129ce7056375dcaaa60030b","user":{"login":"helfper","id":2981969,"node_id":"MDQ6VXNlcjI5ODE5Njk=","avatar_url":"https://avatars1.githubusercontent.com/u/2981969?v=4","gravatar_id":"","url":"https://api.github.com/users/helfper","html_url":"https://github.com/helfper","followers_url":"https://api.github.com/users/helfper/followers","following_url":"https://api.github.com/users/helfper/following{/other_user}","gists_url":"https://api.github.com/users/helfper/gists{/gist_id}","starred_url":"https://api.github.com/users/helfper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/helfper/subscriptions","organizations_url":"https://api.github.com/users/helfper/orgs","repos_url":"https://api.github.com/users/helfper/repos","events_url":"https://api.github.com/users/helfper/events{/privacy}","received_events_url":"https://api.github.com/users/helfper/received_events","type":"User","site_admin":false},"body":"Why isn't the `fallback` in the else here?","created_at":"2018-06-25T09:20:56Z","updated_at":"2018-06-25T09:20:56Z","html_url":"https://github.com/scalatra/scalatra/pull/839#discussion_r197730126","pull_request_url":"https://api.github.com/repos/scalatra/scalatra/pulls/839","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/scalatra/scalatra/pulls/comments/197730126"},"html":{"href":"https://github.com/scalatra/scalatra/pull/839#discussion_r197730126"},"pull_request":{"href":"https://api.github.com/repos/scalatra/scalatra/pulls/839"}}},"pull_request":{"url":"https://api.github.com/repos/scalatra/scalatra/pulls/839","id":196929689,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk2OTI5Njg5","html_url":"https://github.com/scalatra/scalatra/pull/839","diff_url":"https://github.com/scalatra/scalatra/pull/839.diff","patch_url":"https://github.com/scalatra/scalatra/pull/839.patch","issue_url":"https://api.github.com/repos/scalatra/scalatra/issues/839","number":839,"state":"closed","locked":false,"title":"Removed dependency on mime-util","user":{"login":"magnolia-k","id":1701138,"node_id":"MDQ6VXNlcjE3MDExMzg=","avatar_url":"https://avatars3.githubusercontent.com/u/1701138?v=4","gravatar_id":"","url":"https://api.github.com/users/magnolia-k","html_url":"https://github.com/magnolia-k","followers_url":"https://api.github.com/users/magnolia-k/followers","following_url":"https://api.github.com/users/magnolia-k/following{/other_user}","gists_url":"https://api.github.com/users/magnolia-k/gists{/gist_id}","starred_url":"https://api.github.com/users/magnolia-k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/magnolia-k/subscriptions","organizations_url":"https://api.github.com/users/magnolia-k/orgs","repos_url":"https://api.github.com/users/magnolia-k/repos","events_url":"https://api.github.com/users/magnolia-k/events{/privacy}","received_events_url":"https://api.github.com/users/magnolia-k/received_events","type":"User","site_admin":false},"body":"`MimeTypes` used mime-util to guess the MIME Type, but that\r\nmime-util has not been maintained for a long time and now that\r\n`java.net.URLConnection` can do the same thing.\r\n\r\nAlthough mime-util uses magic.mime, the accuracy of guess is high,\r\nbut in generating content-type on the server side, there seems to\r\nbe no scenario where this is a problem ... as it becomes a problem,\r\nwe can set the content-type explicitly.\r\n\r\nAlso, mime-util uses extensions for MIME Type guesses, but can not\r\nadd any extensions.\r\n`java.net.URLConnection` can add any extension to target.\r\n\r\nFor the above reason, replace with `java.net.URLConnection`","created_at":"2018-06-24T02:48:13Z","updated_at":"2018-06-25T09:20:56Z","closed_at":"2018-06-24T10:46:42Z","merged_at":"2018-06-24T10:46:42Z","merge_commit_sha":"2a038af00bea06e1bc97e328be92ad9ec7ccf3b5","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":{"url":"https://api.github.com/repos/scalatra/scalatra/milestones/17","html_url":"https://github.com/scalatra/scalatra/milestone/17","labels_url":"https://api.github.com/repos/scalatra/scalatra/milestones/17/labels","id":2905101,"node_id":"MDk6TWlsZXN0b25lMjkwNTEwMQ==","number":17,"title":"2.7.0","description":"","creator":{"login":"takezoe","id":1094760,"node_id":"MDQ6VXNlcjEwOTQ3NjA=","avatar_url":"https://avatars1.githubusercontent.com/u/1094760?v=4","gravatar_id":"","url":"https://api.github.com/users/takezoe","html_url":"https://github.com/takezoe","followers_url":"https://api.github.com/users/takezoe/followers","following_url":"https://api.github.com/users/takezoe/following{/other_user}","gists_url":"https://api.github.com/users/takezoe/gists{/gist_id}","starred_url":"https://api.github.com/users/takezoe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/takezoe/subscriptions","organizations_url":"https://api.github.com/users/takezoe/orgs","repos_url":"https://api.github.com/users/takezoe/repos","events_url":"https://api.github.com/users/takezoe/events{/privacy}","received_events_url":"https://api.github.com/users/takezoe/received_events","type":"User","site_admin":false},"open_issues":9,"closed_issues":18,"state":"open","created_at":"2017-11-11T08:23:04Z","updated_at":"2018-06-24T18:32:04Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/scalatra/scalatra/pulls/839/commits","review_comments_url":"https://api.github.com/repos/scalatra/scalatra/pulls/839/comments","review_comment_url":"https://api.github.com/repos/scalatra/scalatra/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scalatra/scalatra/issues/839/comments","statuses_url":"https://api.github.com/repos/scalatra/scalatra/statuses/e4ae79604d252b040129ce7056375dcaaa60030b","head":{"label":"magnolia-k:improvement_of_MIME_type_guessing","ref":"improvement_of_MIME_type_guessing","sha":"e4ae79604d252b040129ce7056375dcaaa60030b","user":{"login":"magnolia-k","id":1701138,"node_id":"MDQ6VXNlcjE3MDExMzg=","avatar_url":"https://avatars3.githubusercontent.com/u/1701138?v=4","gravatar_id":"","url":"https://api.github.com/users/magnolia-k","html_url":"https://github.com/magnolia-k","followers_url":"https://api.github.com/users/magnolia-k/followers","following_url":"https://api.github.com/users/magnolia-k/following{/other_user}","gists_url":"https://api.github.com/users/magnolia-k/gists{/gist_id}","starred_url":"https://api.github.com/users/magnolia-k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/magnolia-k/subscriptions","organizations_url":"https://api.github.com/users/magnolia-k/orgs","repos_url":"https://api.github.com/users/magnolia-k/repos","events_url":"https://api.github.com/users/magnolia-k/events{/privacy}","received_events_url":"https://api.github.com/users/magnolia-k/received_events","type":"User","site_admin":false},"repo":{"id":93244756,"node_id":"MDEwOlJlcG9zaXRvcnk5MzI0NDc1Ng==","name":"scalatra","full_name":"magnolia-k/scalatra","owner":{"login":"magnolia-k","id":1701138,"node_id":"MDQ6VXNlcjE3MDExMzg=","avatar_url":"https://avatars3.githubusercontent.com/u/1701138?v=4","gravatar_id":"","url":"https://api.github.com/users/magnolia-k","html_url":"https://github.com/magnolia-k","followers_url":"https://api.github.com/users/magnolia-k/followers","following_url":"https://api.github.com/users/magnolia-k/following{/other_user}","gists_url":"https://api.github.com/users/magnolia-k/gists{/gist_id}","starred_url":"https://api.github.com/users/magnolia-k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/magnolia-k/subscriptions","organizations_url":"https://api.github.com/users/magnolia-k/orgs","repos_url":"https://api.github.com/users/magnolia-k/repos","events_url":"https://api.github.com/users/magnolia-k/events{/privacy}","received_events_url":"https://api.github.com/users/magnolia-k/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/magnolia-k/scalatra","description":"Tiny Scala high-performance, async web framework, inspired by Sinatra","fork":true,"url":"https://api.github.com/repos/magnolia-k/scalatra","forks_url":"https://api.github.com/repos/magnolia-k/scalatra/forks","keys_url":"https://api.github.com/repos/magnolia-k/scalatra/keys{/key_id}","collaborators_url":"https://api.github.com/repos/magnolia-k/scalatra/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/magnolia-k/scalatra/teams","hooks_url":"https://api.github.com/repos/magnolia-k/scalatra/hooks","issue_events_url":"https://api.github.com/repos/magnolia-k/scalatra/issues/events{/number}","events_url":"https://api.github.com/repos/magnolia-k/scalatra/events","assignees_url":"https://api.github.com/repos/magnolia-k/scalatra/assignees{/user}","branches_url":"https://api.github.com/repos/magnolia-k/scalatra/branches{/branch}","tags_url":"https://api.github.com/repos/magnolia-k/scalatra/tags","blobs_url":"https://api.github.com/repos/magnolia-k/scalatra/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/magnolia-k/scalatra/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/magnolia-k/scalatra/git/refs{/sha}","trees_url":"https://api.github.com/repos/magnolia-k/scalatra/git/trees{/sha}","statuses_url":"https://api.github.com/repos/magnolia-k/scalatra/statuses/{sha}","languages_url":"https://api.github.com/repos/magnolia-k/scalatra/languages","stargazers_url":"https://api.github.com/repos/magnolia-k/scalatra/stargazers","contributors_url":"https://api.github.com/repos/magnolia-k/scalatra/contributors","subscribers_url":"https://api.github.com/repos/magnolia-k/scalatra/subscribers","subscription_url":"https://api.github.com/repos/magnolia-k/scalatra/subscription","commits_url":"https://api.github.com/repos/magnolia-k/scalatra/commits{/sha}","git_commits_url":"https://api.github.com/repos/magnolia-k/scalatra/git/commits{/sha}","comments_url":"https://api.github.com/repos/magnolia-k/scalatra/comments{/number}","issue_comment_url":"https://api.github.com/repos/magnolia-k/scalatra/issues/comments{/number}","contents_url":"https://api.github.com/repos/magnolia-k/scalatra/contents/{+path}","compare_url":"https://api.github.com/repos/magnolia-k/scalatra/compare/{base}...{head}","merges_url":"https://api.github.com/repos/magnolia-k/scalatra/merges","archive_url":"https://api.github.com/repos/magnolia-k/scalatra/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/magnolia-k/scalatra/downloads","issues_url":"https://api.github.com/repos/magnolia-k/scalatra/issues{/number}","pulls_url":"https://api.github.com/repos/magnolia-k/scalatra/pulls{/number}","milestones_url":"https://api.github.com/repos/magnolia-k/scalatra/milestones{/number}","notifications_url":"https://api.github.com/repos/magnolia-k/scalatra/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/magnolia-k/scalatra/labels{/name}","releases_url":"https://api.github.com/repos/magnolia-k/scalatra/releases{/id}","deployments_url":"https://api.github.com/repos/magnolia-k/scalatra/deployments","created_at":"2017-06-03T11:49:24Z","updated_at":"2018-06-24T12:59:16Z","pushed_at":"2018-06-24T12:59:15Z","git_url":"git://github.com/magnolia-k/scalatra.git","ssh_url":"git@github.com:magnolia-k/scalatra.git","clone_url":"https://github.com/magnolia-k/scalatra.git","svn_url":"https://github.com/magnolia-k/scalatra","homepage":"http://scalatra.org","size":6069,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_projects":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"2.7.x"}},"base":{"label":"scalatra:2.7.x","ref":"2.7.x","sha":"86d0c1b120723dd80a518ade01ebfa0d99f8626b","user":{"login":"scalatra","id":322549,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMyMjU0OQ==","avatar_url":"https://avatars3.githubusercontent.com/u/322549?v=4","gravatar_id":"","url":"https://api.github.com/users/scalatra","html_url":"https://github.com/scalatra","followers_url":"https://api.github.com/users/scalatra/followers","following_url":"https://api.github.com/users/scalatra/following{/other_user}","gists_url":"https://api.github.com/users/scalatra/gists{/gist_id}","starred_url":"https://api.github.com/users/scalatra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scalatra/subscriptions","organizations_url":"https://api.github.com/users/scalatra/orgs","repos_url":"https://api.github.com/users/scalatra/repos","events_url":"https://api.github.com/users/scalatra/events{/privacy}","received_events_url":"https://api.github.com/users/scalatra/received_events","type":"Organization","site_admin":false},"repo":{"id":214710,"node_id":"MDEwOlJlcG9zaXRvcnkyMTQ3MTA=","name":"scalatra","full_name":"scalatra/scalatra","owner":{"login":"scalatra","id":322549,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMyMjU0OQ==","avatar_url":"https://avatars3.githubusercontent.com/u/322549?v=4","gravatar_id":"","url":"https://api.github.com/users/scalatra","html_url":"https://github.com/scalatra","followers_url":"https://api.github.com/users/scalatra/followers","following_url":"https://api.github.com/users/scalatra/following{/other_user}","gists_url":"https://api.github.com/users/scalatra/gists{/gist_id}","starred_url":"https://api.github.com/users/scalatra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scalatra/subscriptions","organizations_url":"https://api.github.com/users/scalatra/orgs","repos_url":"https://api.github.com/users/scalatra/repos","events_url":"https://api.github.com/users/scalatra/events{/privacy}","received_events_url":"https://api.github.com/users/scalatra/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scalatra/scalatra","description":"Tiny Scala high-performance, async web framework, inspired by Sinatra","fork":false,"url":"https://api.github.com/repos/scalatra/scalatra","forks_url":"https://api.github.com/repos/scalatra/scalatra/forks","keys_url":"https://api.github.com/repos/scalatra/scalatra/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scalatra/scalatra/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scalatra/scalatra/teams","hooks_url":"https://api.github.com/repos/scalatra/scalatra/hooks","issue_events_url":"https://api.github.com/repos/scalatra/scalatra/issues/events{/number}","events_url":"https://api.github.com/repos/scalatra/scalatra/events","assignees_url":"https://api.github.com/repos/scalatra/scalatra/assignees{/user}","branches_url":"https://api.github.com/repos/scalatra/scalatra/branches{/branch}","tags_url":"https://api.github.com/repos/scalatra/scalatra/tags","blobs_url":"https://api.github.com/repos/scalatra/scalatra/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scalatra/scalatra/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scalatra/scalatra/git/refs{/sha}","trees_url":"https://api.github.com/repos/scalatra/scalatra/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scalatra/scalatra/statuses/{sha}","languages_url":"https://api.github.com/repos/scalatra/scalatra/languages","stargazers_url":"https://api.github.com/repos/scalatra/scalatra/stargazers","contributors_url":"https://api.github.com/repos/scalatra/scalatra/contributors","subscribers_url":"https://api.github.com/repos/scalatra/scalatra/subscribers","subscription_url":"https://api.github.com/repos/scalatra/scalatra/subscription","commits_url":"https://api.github.com/repos/scalatra/scalatra/commits{/sha}","git_commits_url":"https://api.github.com/repos/scalatra/scalatra/git/commits{/sha}","comments_url":"https://api.github.com/repos/scalatra/scalatra/comments{/number}","issue_comment_url":"https://api.github.com/repos/scalatra/scalatra/issues/comments{/number}","contents_url":"https://api.github.com/repos/scalatra/scalatra/contents/{+path}","compare_url":"https://api.github.com/repos/scalatra/scalatra/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scalatra/scalatra/merges","archive_url":"https://api.github.com/repos/scalatra/scalatra/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scalatra/scalatra/downloads","issues_url":"https://api.github.com/repos/scalatra/scalatra/issues{/number}","pulls_url":"https://api.github.com/repos/scalatra/scalatra/pulls{/number}","milestones_url":"https://api.github.com/repos/scalatra/scalatra/milestones{/number}","notifications_url":"https://api.github.com/repos/scalatra/scalatra/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scalatra/scalatra/labels{/name}","releases_url":"https://api.github.com/repos/scalatra/scalatra/releases{/id}","deployments_url":"https://api.github.com/repos/scalatra/scalatra/deployments","created_at":"2009-05-31T09:20:32Z","updated_at":"2018-06-24T19:36:07Z","pushed_at":"2018-06-24T10:46:42Z","git_url":"git://github.com/scalatra/scalatra.git","ssh_url":"git@github.com:scalatra/scalatra.git","clone_url":"https://github.com/scalatra/scalatra.git","svn_url":"https://github.com/scalatra/scalatra","homepage":"http://scalatra.org","size":6936,"stargazers_count":2287,"watchers_count":2287,"language":"Scala","has_issues":true,"has_projects":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":329,"mirror_url":null,"archived":false,"open_issues_count":93,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":329,"open_issues":93,"watchers":2287,"default_branch":"2.7.x"}},"_links":{"self":{"href":"https://api.github.com/repos/scalatra/scalatra/pulls/839"},"html":{"href":"https://github.com/scalatra/scalatra/pull/839"},"issue":{"href":"https://api.github.com/repos/scalatra/scalatra/issues/839"},"comments":{"href":"https://api.github.com/repos/scalatra/scalatra/issues/839/comments"},"review_comments":{"href":"https://api.github.com/repos/scalatra/scalatra/pulls/839/comments"},"review_comment":{"href":"https://api.github.com/repos/scalatra/scalatra/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scalatra/scalatra/pulls/839/commits"},"statuses":{"href":"https://api.github.com/repos/scalatra/scalatra/statuses/e4ae79604d252b040129ce7056375dcaaa60030b"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"helfper"}}