karatelabs / karate

Test Automation Made Simple
https://karatelabs.github.io/karate
MIT License
8.32k stars 1.95k forks source link

Create an option to use karate.proceed functionality in JS mocks #2344

Open vincent-hennig opened 1 year ago

vincent-hennig commented 1 year ago

As stated in this question on stackoverflow we would like to use request forwarding while using a javascript mock. Currently this feature does not exist for JS mocks and could be implemented as context.proceed(), saving users the work of manually creating a new http request and handling responses.

vincent-hennig commented 1 year ago

We (@anupamck and I) have already looked into this a bit and found a way to do a forwarding for http requests. However it is proving difficult to do the same for https. To send a new request inside ServerContext.java we are creating a HttpClient using ServerConfig.getHttpClientFactory().apply(request)

This gives us an ArmeriaHttpClient that produces an error when sending a request to an https URL. com.linecorp.armeria.common.stream.ClosedStreamException: received a RST_STREAM frame: PROTOCOL_ERROR

Is there an intended way to use the ArmeriaHttpClient for ssl requests? Looking through the Armeria documentation has so far not proven successful.

ptrthomas commented 1 year ago

@vincent-hennig please take a look at #2048 and let me also tag @ismail-s here for his thoughts

ptrthomas commented 1 year ago

@vincent-hennig meanwhile perhaps using the ApacheHttpClient instead of Armeria should work

vincent-hennig commented 1 year ago

@ptrthomas The Https issue turned out to be due to me not setting up headers correctly. It is working now.

Unfortunatley we ran into a different problem with the ArmeriaHttpClient: When using context.http or our newly created context.proceed the ArmeriaHttpClient just stops responding after a few dozen requests have been sent. Every request then gets a timeout after 30 seconds. While investigating this we saw that it looks like every call to context.http() creates at least one additional thread that simply never shuts down again. Could there be some Problem with cleaning up open connections/threads inside the ArmeriaHttpClient?

ptrthomas commented 1 year ago

@vincent-hennig yes quite likely, it may need investigating