API Connect

 View Only
  • 1.  Is content-type sent by default for a post request?

    Posted 9 days ago

    We have a yaml file hosted on API Connect which is sending a Post request to a backend (with no body in the request).  If content-type is sent with any value other than blank, we are returned a 415 Unsupported Media Type.  If I try sending a request through API Connect without specifying a content-type header I am also getting a 415.  Is there a way to specify that no content-type header is needed on the request?  The only way this is successful is if I declare the content-type header and set it to a blank value.  



    ------------------------------
    Jeff Bennett
    ------------------------------


  • 2.  RE: Is content-type sent by default for a post request?

    Posted 9 days ago

    Is that your api or your backend that is the problem?

    The content type header should be sent when content is sent, the http spec says so. You need to fix your api to use the correct content type header values not remove it.

    check the consumes and produces attributes in your openapi document and ensure they are correct for the mime type your api accepts and returns. 
    then check the backend.



    ------------------------------
    Chris Dudley
    ------------------------------



  • 3.  RE: Is content-type sent by default for a post request?

    Posted 7 days ago

    Hi Jeff,
    Assuming your using an API Gateway API, in the API, on the invoke policy, you can specify a "blocklist" where you could specify that the Content-Type header would not be sent to the backend.  If using a v5 compatible Gateway, you'd need to clear message.headers.content-type prior to the invoke policy.
    Regards,

    Steve Linn



    ------------------------------
    Steve Linn
    Senior Consulting I/T Specialist
    IBM
    ------------------------------



  • 4.  RE: Is content-type sent by default for a post request?

    Posted 2 days ago

    Thanks Steve.  I tried putting in a blocklist after you suggested this.  So it now throws a 415 whether I include content-type or not.  If I call the backend directly and don't include content-type, I get a 200.  Does API Connect send a content-type header by default?  Even if content-type is included in the blocklist?  



    ------------------------------
    Jeff Bennett
    ------------------------------



  • 5.  RE: Is content-type sent by default for a post request?

    Posted 2 days ago

    Hi Jeff,
    I took a simple API that sends a request to a backend that echos back the request body and headers and then posted a JSON payload with a content-type of application/json to that API.  Without the blocklist on the headers, I see the application/json content-type in my response, but with the blocklist, the content-type header is omitted in my response.  Here's my policy:

      assembly:
        execute:
          - invoke:
              version: 2.0.0
              title: invoke
              backend-type: detect
              header-control:
                type: blocklist
                values:
                  - Content-Type
              parameter-control:
                type: allowlist
                values: []
              timeout: 60
              verb: keep
              chunked-uploads: true
              persistent-connection: true
              target-url: $(target-url)
              follow-redirects: false
              inject-proxy-headers: true

    When you call the backend directly without a Content-Type headers, how are you doing this? curl, postman, soapui?  I've found that these tools tend to inject a content-type request header for you if you don't explicitly provide one. For example curl injects Content-Type: application/x-www-form-urlencoded Are you sure the backend is receiving no content-type header in your direct case?

    Best Regards,
    Steve Linn



    ------------------------------
    Steve Linn
    Senior Consulting I/T Specialist
    IBM
    ------------------------------



  • 6.  RE: Is content-type sent by default for a post request?

    Posted 2 days ago

    Hi Steve.

    This is how I have it set:

    assembly:
        execute:
        - invoke:
            title: invoke
            version: 2.0.0
            verb: keep
            target-url: $(target-url)/hr-data-contact-center$(api.operation.path)$(request.search)
            follow-redirects: false
            timeout: 60
            parameter-control:
              type: allowlist
              values: []
            header-control:
              type: blocklist
              values:
                - content-type
            inject-proxy-headers: true

    I'm testing this via postman requests.  When I switch to the direct backend url.. I am able to remove the content-type header and get a 200 response.  When I do the same via my api connect url I am getting a 415 unsupported media type (also using postman).  

    When I have the blocklist piece added, I get a 415 regardless.  When It's not present, I can send content-type with a blank value and it works.  With anything other than blank, I get a 415.  And if I remove it all together, I get a 415.



    ------------------------------
    Jeff Bennett
    ------------------------------