Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: michaelklishin/pantomime
base: 63feacdc29
...
head fork: michaelklishin/pantomime
compare: 03f8376bce
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
9 ChangeLog.md
@@ -1,3 +1,12 @@
+## Changes between Pantomime 1.3.0-beta2 and 1.3.0-rc1
+
+### New functions in pantomime.media.MediaTypeOps
+
+New functions that return media type parameters and charset:
+
+* `pantomime.media/has-parameters?`
+
+
## Changes between Pantomime 1.3.0-beta1 and 1.3.0-beta2
### New functions in pantomime.media.MediaTypeOps
View
7 src/pantomime/media.clj
@@ -40,6 +40,7 @@
(defprotocol MediaTypeOps
(base-type [input] "Returns base media type for given input, for example, text/html for text/html; charset=UTF-8")
(parameters-of [input] "Returns optional parameters map for given input")
+ (has-parameters? [input] "Returns true if given content type has parameters, false otherwise")
(charset-of [input] "Returns optional charset given input, for example, UTF-8 for text/html; charset=UTF-8 and nil for text/html")
(application? [input] "Returns true if input is an application/* media type, false otherwise")
(text? [input] "Returns true if input is a text/* media type, false otherwise")
@@ -58,6 +59,9 @@
(parameters-of
[^String input]
(parameters-of (parse input)))
+ (has-parameters?
+ [^String input]
+ (has-parameters? (parse input)))
(charset-of
[^String input]
(charset-of (parse input)))
@@ -92,6 +96,9 @@
[^MediaType input]
(when-let [^Map jm (.getParameters input)]
(into {} jm)))
+ (has-parameters?
+ [^MediaType input]
+ (.hasParameters input))
(charset-of
[^MediaType input]
(when-let [m (parameters-of input)]
View
13 test/pantomime/test/media.clj → test/pantomime/test/media_test.clj
@@ -1,7 +1,7 @@
-(ns pantomime.test.media
- (:use [clojure.test])
+(ns pantomime.test.media-test
+ (:use clojure.test)
(:require [pantomime.media :as media])
- (:import [org.apache.tika.mime MediaType]))
+ (:import org.apache.tika.mime.MediaType))
(deftest test-media-type-named
@@ -24,6 +24,13 @@
(is (nil? (media/charset-of "text/html")))
(is (nil? (media/charset-of "text/html; key=val"))))
+(deftest test-parameters-of
+ (let [with-params (media/parse "text/html; charset=UTF-8")
+ without-params (media/parse "text/html")]
+ (is (= {"charset" "UTF-8"} (media/parameters-of with-params)))
+ (is (media/has-parameters? with-params))
+ (is (= {} (media/parameters-of without-params)))
+ (is (not (media/has-parameters? without-params)))))
(deftest test-multipart-predicate
(are [mt] (is (media/multipart? mt))
View
7 test/pantomime/test/mime.clj → test/pantomime/test/mime_test.clj
@@ -1,9 +1,8 @@
-(ns pantomime.test.mime
- (:use [pantomime.mime]
- [clojure.test])
+(ns pantomime.test.mime-test
+ (:use pantomime.mime clojure.test)
(:require [clojure.java.io :as io])
(:import [java.io File FileInputStream]
- [java.net URL]))
+ java.net.URL))
(deftest test-content-type-detection

No commit comments for this range

Something went wrong with that request. Please try again.