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

POST p:http-request gives "MIME type may not contain reserved characters" #290

Open
gimsieke opened this Issue Apr 7, 2019 · 4 comments

Comments

Projects
None yet
2 participants
@gimsieke
Copy link
Contributor

gimsieke commented Apr 7, 2019

This happens first in 1.1.25 (all Saxon versions) and is probably related to the upgrade to httpclient-4.5.5.jar

Running this pipeline:

<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" 
  xmlns:cx="http://xmlcalabash.com/ns/extensions"
  xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0" name="mystep">

  <p:input port="source" primary="true">
    <p:inline><doc/></p:inline>
  </p:input>
  <p:output port="result" primary="true">
    <p:pipe port="result" step="post"/>
  </p:output>

  <p:import href="http://xmlcalabash.com/extension/steps/library-1.0.xpl"/>
  
  <p:in-scope-names name="vars"/>
  
  <p:template name="http-request">
    <p:input port="template">
      <p:inline>
        <c:request href="http://httpbin.org/post" method="POST" detailed="true">
          <c:multipart content-type="multipart/form-data" boundary="=-=-=-=-=">
            <c:body content-type="application/xml" disposition='form-data; name="data"; filename="test.xml"'>
              {/*}
            </c:body>
          </c:multipart>
        </c:request>
      </p:inline>
    </p:input>
    <p:input port="source">
      <p:pipe step="mystep" port="source"/>
    </p:input>
    <p:input port="parameters">
      <p:pipe step="vars" port="result"/>
    </p:input>
  </p:template>

  <p:http-request name="post"/>
  
  <p:store href="result.json" cx:decode="true">
    <p:input port="source" select="/c:response/c:body"/>
  </p:store>
</p:declare-step>

succeeds in all versions up to and including 1.1.24. It fails with

ERROR: Pipeline failed: MIME type may not contain reserved characters

in 1.1.25 and newer.

@ndw

This comment has been minimized.

Copy link
Owner

ndw commented Apr 9, 2019

I believe that it's related to the 4.4.6 version of the httpclient library:

elastic/elasticsearch#26438 (comment)

(My build.gradle file is only requesting 4.4.5, but I see that 4.4.9 is being pulled in.)

The content type includes the boundary parameter and therefore contains a ";" which is what the 4.4.6+ version is complaining about.

AFAICT, the MultipartEntityBuilder is the new/right way to build multipart bodies. However, it appears to have a completely fatal flaw in that there's no provision for providing additional headers for the various parts.

https://stackoverflow.com/questions/46076359/adding-content-id-header-in-multipart-entity

I have no idea what to do with this.

In the short term, if you can force your app to use the 4.4.5 httpclient library, I think the problem will go away.

@gimsieke

This comment has been minimized.

Copy link
Contributor Author

gimsieke commented Apr 9, 2019

I replaced httpclient-4.5.5.jar and httpcore-4.4.9.jar with httpclient-4.5.2.jar and httpcore-4.4.5.jar in the lib directory of the extracted 1.1.22-99 release zip, but then I get:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/HttpRequestRetryHandler
So maybe you’re already using some newer httpclient functionality?

@ndw

This comment has been minimized.

Copy link
Owner

ndw commented Apr 10, 2019

I made a small amount of progress with the MultipartEntityBuilder but it seems fundamentally designed with form submissions in mind. I've just joined the httpclient-users mailing list, hopefully I can get some more answers from there.

☹️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.