Added support for multipart with content type, fixes gh-599
This commit is contained in:
@@ -71,6 +71,10 @@ class Common {
|
||||
return new NamedProperty(name, value)
|
||||
}
|
||||
|
||||
NamedProperty named(DslProperty name, DslProperty value, DslProperty contentType) {
|
||||
return new NamedProperty(name, value, contentType)
|
||||
}
|
||||
|
||||
NamedProperty named(Map<String, DslProperty> namedMap){
|
||||
return new NamedProperty(namedMap)
|
||||
}
|
||||
|
||||
@@ -33,16 +33,37 @@ class NamedProperty {
|
||||
|
||||
private static final String NAME = 'name'
|
||||
private static final String CONTENT = 'content'
|
||||
private static final String CONTENT_TYPE = 'contentType'
|
||||
|
||||
DslProperty name
|
||||
DslProperty value
|
||||
DslProperty contentType
|
||||
|
||||
NamedProperty(DslProperty name, DslProperty value) {
|
||||
this.name = name
|
||||
this.value = value
|
||||
this.contentType = null
|
||||
}
|
||||
|
||||
NamedProperty(DslProperty name, DslProperty value, DslProperty contentType) {
|
||||
this.name = name
|
||||
this.value = value
|
||||
this.contentType = contentType
|
||||
}
|
||||
|
||||
NamedProperty(Map<String, DslProperty> namedMap) {
|
||||
this(namedMap?.get(NAME), namedMap?.get(CONTENT))
|
||||
this(asDslProperty(namedMap?.get(NAME)),
|
||||
asDslProperty(namedMap?.get(CONTENT)),
|
||||
asDslProperty(namedMap?.get(CONTENT_TYPE)))
|
||||
}
|
||||
|
||||
static DslProperty asDslProperty(Object o) {
|
||||
if (o == null) {
|
||||
return null
|
||||
}
|
||||
if (o instanceof DslProperty) {
|
||||
return o
|
||||
}
|
||||
return new DslProperty(o)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,8 +142,18 @@ class RegexPatterns {
|
||||
return ".*--(.*)\r\nContent-Disposition: form-data; name=\"$name\"\r\n(Content-Type: .*\r\n)?(Content-Transfer-Encoding: .*\r\n)?(Content-Length: \\d+\r\n)?\r\n$value\r\n--\\1.*"
|
||||
}
|
||||
|
||||
static String multipartFile(Object name, Object filename, Object content) {
|
||||
return ".*--(.*)\r\nContent-Disposition: form-data; name=\"$name\"; filename=\"$filename\"\r\n(Content-Type: .*\r\n)?(Content-Transfer-Encoding: .*\r\n)?(Content-Length: \\d+\r\n)?\r\n$content\r\n--\\1.*";
|
||||
static String multipartFile(Object name, Object filename, Object content, Object contentType) {
|
||||
return ".*--(.*)\r\nContent-Disposition: form-data; name=\"$name\"; filename=\"$filename\"\r\n(Content-Type: ${toContentType(contentType)}\r\n)?(Content-Transfer-Encoding: .*\r\n)?(Content-Length: \\d+\r\n)?\r\n$content\r\n--\\1.*";
|
||||
}
|
||||
|
||||
private static String toContentType(Object contentType) {
|
||||
if (contentType == null) {
|
||||
return '.*'
|
||||
}
|
||||
if (contentType instanceof Pattern) {
|
||||
return contentType.pattern()
|
||||
}
|
||||
return contentType.toString()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user