Skip to content

Commit

Permalink
LDEV-944 ignore mimeType when httpparam type="body"
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Jan 21, 2025
1 parent c3d3057 commit a7b9534
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions core/src/main/java/lucee/runtime/tag/Http.java
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ else if (this.method == METHOD_PATCH) {
else if (type == HttpParamBean.TYPE_FORM) {
hasForm = true;
if (this.method == METHOD_GET)
throw new ApplicationException("httpparam with type formfield can only be used when the method attribute of the parent http tag is set to post");
throw new ApplicationException("Tag [httpparam] with [type=formfield] can only be used when the [method] is set to [post]");
if (eeReqPost != null) {
if (doMultiPart) {
parts.add(new FormBodyPart(param.getName(), new StringBody(param.getValueAsString(), CharsetUtil.toCharset(charset))));
Expand Down Expand Up @@ -925,7 +925,7 @@ else if (type == HttpParamBean.TYPE_COOKIE) {
// File
else if (type == HttpParamBean.TYPE_FILE) {
hasForm = true;
if (this.method == METHOD_GET) throw new ApplicationException("httpparam type file can't only be used, when method of the tag http equal post");
if (this.method == METHOD_GET) throw new ApplicationException("Tag [httpparam] attribute [type=file] can only be used, when [method] is [post]");
// if(param.getFile()==null) throw new ApplicationException("httpparam type file can't only be used,
// when method of the tag http equal
// post");
Expand All @@ -946,7 +946,7 @@ else if (type == HttpParamBean.TYPE_FILE) {
// ResourcePartSource(param.getFile()),getContentType(param),_charset));
}
catch (FileNotFoundException e) {
throw new ApplicationException("can't upload file, path is invalid", e.getMessage());
throw new ApplicationException("Can't upload file, path is invalid", e.getMessage());
}
}
}
Expand All @@ -963,21 +963,22 @@ else if (type == HttpParamBean.TYPE_XML) {
hasBody = true;
hasContentType = true;
req.addHeader("Content-type", mt + "; charset=" + cs);
if (eeReq == null) throw new ApplicationException("type xml is only supported for methods get, delete, post, and put");
if (eeReq == null) throw new ApplicationException("Tag [httpparam] attribute [type=xml] is only supported for methods [get, delete, post, and put]");
HTTPEngine4Impl.setBody(eeReq, param.getValueAsString(), mt, cs);
}
// Body
else if (type == HttpParamBean.TYPE_BODY) {
ContentType ct = HTTPUtil.toContentType(param.getMimeType(), null);
if (!StringUtil.isEmpty(param.getMimeType())) throw new ApplicationException("Tag [httpparam] attribute [mimeType] is only supported for [type=file]");
//ContentType ct = null;

String mt = null;
if (ct != null && !StringUtil.isEmpty(ct.getMimeType(), true)) mt = ct.getMimeType();
//if (ct != null && !StringUtil.isEmpty(ct.getMimeType(), true)) mt = ct.getMimeType();

String cs = charset;
if (ct != null && !StringUtil.isEmpty(ct.getCharset(), true)) cs = ct.getCharset();
//if (ct != null && !StringUtil.isEmpty(ct.getCharset(), true)) cs = ct.getCharset();

hasBody = true;
if (eeReq == null) throw new ApplicationException("type body is only supported for methods get, delete, post, and put");
if (eeReq == null) throw new ApplicationException("Tag [httpparam] attribute [type=body] is only supported for methods [get, delete, post, and put]");
HTTPEngine4Impl.setBody(eeReq, param.getValue(), mt, cs);

}
Expand Down

0 comments on commit a7b9534

Please sign in to comment.