Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LDEV-944 ignore mimeType when httpparam type="body" #2480

Open
wants to merge 2 commits into
base: 6.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ else if (Decision.isCastableToBinary(value, false)) {
return new EmptyHttpEntity(ct);
}
if (wasNull && !StringUtil.isEmpty(charset, true)) return new StringEntity(str, charset.trim());
else return new StringEntity(str, ct);
return new StringEntity(str, ct);
}
}
catch (Exception e) {
Expand Down
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
Loading