diff --git a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/KiotaClientFactory.java b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/KiotaClientFactory.java index 5996739d..992bb0ca 100644 --- a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/KiotaClientFactory.java +++ b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/KiotaClientFactory.java @@ -136,30 +136,33 @@ private KiotaClientFactory() {} } final List handlers = new ArrayList<>(); + // orders matter as they are executed in a chain + // interceptors that only modify the request should be added first + // interceptors that read the response should be added last handlers.add( - uriReplacementOption != null - ? new UrlReplaceHandler(uriReplacementOption) - : new UrlReplaceHandler()); - handlers.add( - retryHandlerOption != null - ? new RetryHandler(retryHandlerOption) - : new RetryHandler()); - handlers.add( - redirectHandlerOption != null - ? new RedirectHandler(redirectHandlerOption) - : new RedirectHandler()); + userAgentHandlerOption != null + ? new UserAgentHandler(userAgentHandlerOption) + : new UserAgentHandler()); handlers.add( parametersNameDecodingOption != null ? new ParametersNameDecodingHandler(parametersNameDecodingOption) : new ParametersNameDecodingHandler()); handlers.add( - userAgentHandlerOption != null - ? new UserAgentHandler(userAgentHandlerOption) - : new UserAgentHandler()); + uriReplacementOption != null + ? new UrlReplaceHandler(uriReplacementOption) + : new UrlReplaceHandler()); handlers.add( headersInspectionHandlerOption != null ? new HeadersInspectionHandler(headersInspectionHandlerOption) : new HeadersInspectionHandler()); + handlers.add( + redirectHandlerOption != null + ? new RedirectHandler(redirectHandlerOption) + : new RedirectHandler()); + handlers.add( + retryHandlerOption != null + ? new RetryHandler(retryHandlerOption) + : new RetryHandler()); return handlers.toArray(new Interceptor[0]); }