Permalink
Browse files

! http: allow creation of custom MediaTypes with '*' as a subtype whe…

…n called by the parser, fixes #529
  • Loading branch information...
jrudolph committed Oct 8, 2013
1 parent baa3b80 commit e058a4316893c87903a213c4d75f7955b6a5cdaf
@@ -166,6 +166,10 @@ class HttpHeaderParserSpec extends Specification {
parseAndCache("Host: spray.io:123\r\nx")("HOST: spray.io:123\r\nx") === Host("spray.io", 123)
}
+ "parse and cache an invalid modelled header as RawHeader" in new TestSetup() {
+ parseAndCache("Content-Type: abc:123\r\nx")() === RawHeader("Content-Type", "abc:123")
+ }
+
"parse and cache a raw header" in new TestSetup(primed = false) {
insert("hello: bob", 'Hello)
val (ixA, headerA) = parseLine("Fancy-Pants: foo\r\nx")
@@ -169,9 +169,9 @@ object MediaType {
*/
def custom(mainType: String, subType: String, compressible: Boolean = false, binary: Boolean = false,
fileExtensions: Seq[String] = Nil, parameters: Map[String, String] = Map.empty,
- qValue: Double = Double.NaN): MediaType = {
+ qValue: Double = Double.NaN, allowArbitrarySubtypes: Boolean = false): MediaType = {
require(mainType != "multipart", "Cannot create a MultipartMediaType here, use `multipart.apply` instead!")
- require(subType != "*", "Cannot create a MediaRange here, use `MediaRange.custom` instead!")
+ require(allowArbitrarySubtypes || subType != "*", "Cannot create a MediaRange here, use `MediaRange.custom` instead!")
val (value, params, q) = prepare(mainType, subType, parameters, qValue)
new NonMultipartMediaType(value, mainType, subType, compressible, binary, fileExtensions, params, q) with MainTypeBased
}
@@ -37,7 +37,7 @@ private[parser] trait CommonActions {
}
case mainLower
val registered = if (parameters.isEmpty) MediaTypes.getForKey((mainLower, subType.toLowerCase)) else None
- registered getOrElse MediaType.custom(mainType, subType, parameters = parameters)
+ registered getOrElse MediaType.custom(mainType, subType, parameters = parameters, allowArbitrarySubtypes = true)
}
}
@@ -176,6 +176,8 @@ class HttpHeaderSpec extends Specification {
`Content-Type`(ContentType(`multipart/mixed` withBoundary "ABC123"))
"Content-Type: multipart/mixed; boundary=\"ABC/123\"" =!=
`Content-Type`(ContentType(`multipart/mixed` withBoundary "ABC/123"))
+ "Content-Type: application/*" =!=
+ `Content-Type`(ContentType(MediaType.custom("application", "*", allowArbitrarySubtypes = true)))
}
"Cookie" in {

0 comments on commit e058a43

Please sign in to comment.