package com.github.dtrunk90.recaptcha.spring.web.servlet.handler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class RecaptchaHandlerInterceptor extends HandlerInterceptorAdapter {

	public static final String RECAPTCHA_SITE_KEY_ATTRIBUTE_NAME = "recaptchaSiteKey";

	@Value("${recaptcha.site-key}")
	private String recaptchaSiteKey;

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
		if (modelAndView != null) {
			modelAndView.addObject(RECAPTCHA_SITE_KEY_ATTRIBUTE_NAME, recaptchaSiteKey);
		}
	}

}

@@ -339,16 +339,74 @@
 Adapter;
+%0Aimport org.springframework.web.servlet.view.RedirectView;
 %0A%0Apublic
@@ -794,16 +794,150 @@
  != null
+ && modelAndView.hasView() && !(modelAndView.getView() instanceof RedirectView) && !modelAndView.getViewName().startsWith(%22redirect:%22)
 ) %7B%0A%09%09%09m

Add recaptchaSiteKey model attribute not if its a redirect