[
https://issues.apache.org/jira/browse/NIFI-1620?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15333024#comment-15333024
]
ASF GitHub Bot commented on NIFI-1620:
--------------------------------------
Github user taftster commented on a diff in the pull request:
https://github.com/apache/nifi/pull/272#discussion_r67284145
--- Diff:
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java
---
@@ -761,24 +771,38 @@ private Request configureRequest(final ProcessContext
context, final ProcessSess
}
private RequestBody getRequestBodyToSend(final ProcessSession session,
final ProcessContext context, final FlowFile requestFlowFile) {
- return new RequestBody() {
- @Override
- public MediaType contentType() {
- String contentType =
context.getProperty(PROP_CONTENT_TYPE).evaluateAttributeExpressions(requestFlowFile).getValue();
- contentType = StringUtils.isBlank(contentType) ?
DEFAULT_CONTENT_TYPE : contentType;
- return MediaType.parse(contentType);
- }
+ if(context.getProperty(PROP_SEND_BODY).asBoolean()) {
+ return new RequestBody() {
+ @Override
+ public MediaType contentType() {
+ String contentType =
context.getProperty(PROP_CONTENT_TYPE).evaluateAttributeExpressions(requestFlowFile).getValue();
+ contentType = StringUtils.isBlank(contentType) ?
DEFAULT_CONTENT_TYPE : contentType;
+ return MediaType.parse(contentType);
+ }
- @Override
- public void writeTo(BufferedSink sink) throws IOException {
- session.exportTo(requestFlowFile, sink.outputStream());
- }
+ @Override
+ public void writeTo(BufferedSink sink) throws IOException {
+ session.exportTo(requestFlowFile, sink.outputStream());
+ }
- @Override
- public long contentLength(){
- return useChunked ? -1 : requestFlowFile.getSize();
- }
- };
+ @Override
+ public long contentLength(){
+ return useChunked ? -1 : requestFlowFile.getSize();
+ }
+ };
+ } else {
+ return new RequestBody() {
+ @Override
+ public void writeTo(BufferedSink sink) throws IOException {
+ sink.writeUtf8("");
+ }
+
+ @Override
+ public MediaType contentType() {
+ return MediaType.parse("");
+ }
+ };
--- End diff --
For this 'else' clause, it would probably be better to use a RequstBody
static factory. Something like:
`return RequestBody.create(null, new byte[0]);`
I'm not sure the proper way to specific an empty MediaType, though. I think
reading the MediaType javadoc, my hunch is that MediaType.parse("") should
return null (since empty string is an invalid type).
> Allow empty Content-Type in InvokeHTTP processor
> ------------------------------------------------
>
> Key: NIFI-1620
> URL: https://issues.apache.org/jira/browse/NIFI-1620
> Project: Apache NiFi
> Issue Type: Bug
> Components: Extensions
> Affects Versions: 0.5.1
> Reporter: Pierre Villard
> Assignee: Pierre Villard
> Fix For: 1.0.0, 0.7.0
>
>
> External API could expect a POST request without a Content-Type property or
> at least with this property empty:
> *Error example:*
> {quote}
> You provided a non-empty HTTP "Content-Type" header ("application/json").
> This API function requires that the header be missing or empty.
> {quote}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)