Пример #1
0
 private void handleCookies(HttpResponse response) {
   String cookieString = request.headers().get(HttpHeaderNames.COOKIE);
   boolean i18nextFound = false;
   if (cookieString != null) {
     Set<Cookie> cookies = ServerCookieDecoder.LAX.decode(cookieString);
     if (!cookies.isEmpty()) {
       // Reset the sessions if necessary.
       boolean findSession = false;
       for (Cookie cookie : cookies) {
         if (cookie
             .name()
             .equalsIgnoreCase(R66SESSION + Configuration.configuration.getHOST_ID())) {
           if (newSession) {
             findSession = false;
           } else {
             findSession = true;
             response
                 .headers()
                 .add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.LAX.encode(cookie));
           }
         } else if (cookie.name().equalsIgnoreCase(I18NEXT)) {
           i18nextFound = true;
           cookie.setValue(lang);
           response
               .headers()
               .add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.LAX.encode(cookie));
         } else {
           response
               .headers()
               .add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.LAX.encode(cookie));
         }
       }
       if (!i18nextFound) {
         Cookie cookie = new DefaultCookie(I18NEXT, lang);
         response
             .headers()
             .add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.LAX.encode(cookie));
       }
       newSession = false;
       if (!findSession) {
         if (admin != null) {
           response
               .headers()
               .add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.LAX.encode(admin));
           logger.debug("AddSession: " + uriRequest + ":{}", admin);
         }
       }
     }
   } else {
     Cookie cookie = new DefaultCookie(I18NEXT, lang);
     response.headers().add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.LAX.encode(cookie));
     if (admin != null) {
       logger.debug("AddSession: " + uriRequest + ":{}", admin);
       response.headers().add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.LAX.encode(admin));
     }
   }
 }
 private void setCookies(HttpResponse response, DefaultFullHttpResponse httpServletResponse) {
   if (response.getCookies() != null) {
     List<Cookie> cookieValues = new ArrayList<Cookie>();
     for (org.mockserver.model.Cookie cookie : response.getCookies()) {
       cookieValues.add(
           new DefaultCookie(cookie.getName().getValue(), cookie.getValue().getValue()));
     }
     if (!cookieValues.isEmpty()) {
       httpServletResponse.headers().add(SET_COOKIE, ServerCookieEncoder.LAX.encode(cookieValues));
     }
   }
 }