Automating access token refreshing via interceptors in axios

I may have found a way much simpler to handle this : use axios.interceptors.response.eject() to disable the interceptor when I call the /api/refresh_token endpoint, and re-enable it after. The code : /** * Wrap the interceptor in a function, so that i can be re-instantiated */ function createAxiosResponseInterceptor() { const interceptor = axios.interceptors.response.use( (response) => … Read more

Intercept fetch() API requests and responses in JavaScript

Existing answers show the general structure for mocking fetch in the browser but omit important details. The accepted answer shows the general pattern for replacing the window.fetch function with custom implementation that intercepts the call and forwards the arguments to fetch. However, the pattern shown doesn’t let the interception function do anything with the response … Read more

How to use angular2 http API for tracking upload/download progress

As of Angular 4.3.x and beyond versions, it can be achieved using the new HttpClient from @angular/common/http. Read the Listening to progress events section. Simple upload example (copied from the section mentioned above): const req = new HttpRequest(‘POST’, ‘/upload/file’, file, { reportProgress: true, }); http.request(req).subscribe(event => { // Via this API, you get access to … Read more

How To Modify The Raw XML message of an Outbound CXF Request?

Based on the first comment, I created an abstract class which can easily be used to change the whole soap envelope. Just in case someone wants a ready-to-use code part. import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import org.apache.commons.io.IOUtils; import org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor; import org.apache.cxf.io.CachedOutputStream; import org.apache.cxf.message.Message; import org.apache.cxf.phase.AbstractPhaseInterceptor; import org.apache.cxf.phase.Phase; import org.apache.log4j.Logger; /** * http://www.mastertheboss.com/jboss-web-services/apache-cxf-interceptors * http://stackoverflow.com/questions/6915428/how-to-modify-the-raw-xml-message-of-an-outbound-cxf-request … Read more

GNU gcc/ld – wrapping a call to symbol with caller and callee defined in the same object file

You have to weaken and globalize the symbol using objcopy. -W symbolname –weaken-symbol=symbolname Make symbol symbolname weak. This option may be given more than once. –globalize-symbol=symbolname Give symbol symbolname global scoping so that it is visible outside of the file in which it is defined. This option may be given more than once. This worked … Read more

How to intercept all AJAX requests made by different JS libraries

This type of function hooking is perfectly safe and is done regularly on other methods for other reasons. And, the only performance impact is really only one extra function call for each .open() plus whatever code you execute yourself which is probably immaterial when a networking call is involved. In IE, this won’t catch any … Read more