gstroup / apimocker

node.js module to run a simple http server for mock service responses.
MIT License
280 stars 81 forks source link

How to mock 'Content-Type: application/soap+xml' requests? #36

Closed asnov closed 8 years ago

asnov commented 8 years ago

Hello Guys! I am trying to mock some soap xml API but I stucked with the problem that API receives gzip-ed request only So I have to send gzip-ed request from my app. The question is how I can receive a gzip-ed request by apimock? I have the next config for apimock: IIS + iisnode + node.js + apimock (using regexp type switchs to parse xml). Requests are gzip-ed xml files. Thank you!

gstroup commented 8 years ago

Hi, Good question.  Can you be a little more specific?  Exactly what request are you sending?  A 'curl' command would be great.  And what response do you see?   You should be able to send a gzip request to apimocker, but I haven't tried myself. Thanks.    -Greg From: Alex Novikov notifications@github.com To: gstroup/apimocker apimocker@noreply.github.com Sent: Friday, December 4, 2015 6:58 AM Subject: [apimocker] Mock 'accept-encoding': 'gzip, deflate' requests (#36)

Hello Guys! I am trying to mock some API but I stucked with the problem that API receives gzip-ed request only So I have to send gzip-ed request from my app. The question is how I can receive a gzip-ed request by apimock? Thank you!— Reply to this email directly or view it on GitHub.

asnov commented 8 years ago

Hi @gstroup , Thank you for your answer. My future investigation discovered that my issue is not about gzip encoding but about xml encoding.

I tried this command: curl -X POST -d @200_request.xml http://localhost/Service.svc It works fine. The apimocker parses the xml using switch type regexp, finds the string parameter, compares it with the switchResponses and gives me the right mockFile.

But when I try the next command to send such headers as the library that I mock does: curl -X POST -H "Content-Type: application/soap+xml; charset=utf-8" -d @200_request.xml http://localhost/Service.svc The regexp does not find a string and gives me default mockFile.

Debugger shows me that in first case the request body is {'<Envelope xmlns': '...long string with the rest of the xml file...'}. It is not right but anyway it works for me. In the second case the request body is empty: {}. So I've read docs for body-parser that you use and I conclude that body-parser does not proceed the request with the "Content-Type: application/soap+xml".

Any ideas?

gstroup commented 8 years ago

Thanks for contributing! Looks like a simple fix. I'd like to add at least one test, and I'll merge it in the next few days. Thanks.

-Greg