Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Commit 
							
							·
						
						32a0c60
	
1
								Parent(s):
							
							f5b7aab
								
changes
Browse files
    	
        src/main/java/ai/giskard/learnspringwebsockets/LearnSpringWebsocketsApplication.java
    CHANGED
    
    | @@ -3,6 +3,7 @@ package ai.giskard.learnspringwebsockets; | |
| 3 | 
             
            import jakarta.servlet.FilterChain;
         | 
| 4 | 
             
            import jakarta.servlet.ServletException;
         | 
| 5 | 
             
            import jakarta.servlet.http.HttpServletRequest;
         | 
|  | |
| 6 | 
             
            import jakarta.servlet.http.HttpServletResponse;
         | 
| 7 | 
             
            import org.springframework.boot.SpringApplication;
         | 
| 8 | 
             
            import org.springframework.boot.autoconfigure.SpringBootApplication;
         | 
| @@ -11,7 +12,10 @@ import org.springframework.web.filter.OncePerRequestFilter; | |
| 11 |  | 
| 12 | 
             
            import java.io.IOException;
         | 
| 13 | 
             
            import java.text.MessageFormat;
         | 
|  | |
| 14 | 
             
            import java.util.Enumeration;
         | 
|  | |
|  | |
| 15 |  | 
| 16 | 
             
            @SpringBootApplication
         | 
| 17 | 
             
            public class LearnSpringWebsocketsApplication {
         | 
| @@ -26,15 +30,25 @@ public class LearnSpringWebsocketsApplication { | |
| 26 | 
             
                    @Override
         | 
| 27 | 
             
                    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
         | 
| 28 | 
             
                            throws ServletException, IOException {
         | 
| 29 | 
            -
             | 
| 30 | 
            -
                         | 
| 31 | 
            -
             | 
| 32 | 
            -
                             | 
| 33 | 
            -
                                 | 
| 34 | 
            -
             | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 35 | 
             
                            }
         | 
| 36 | 
            -
                        }
         | 
| 37 | 
            -
                        filterChain.doFilter( | 
| 38 | 
             
                    }
         | 
| 39 | 
             
                }
         | 
| 40 |  | 
|  | |
| 3 | 
             
            import jakarta.servlet.FilterChain;
         | 
| 4 | 
             
            import jakarta.servlet.ServletException;
         | 
| 5 | 
             
            import jakarta.servlet.http.HttpServletRequest;
         | 
| 6 | 
            +
            import jakarta.servlet.http.HttpServletRequestWrapper;
         | 
| 7 | 
             
            import jakarta.servlet.http.HttpServletResponse;
         | 
| 8 | 
             
            import org.springframework.boot.SpringApplication;
         | 
| 9 | 
             
            import org.springframework.boot.autoconfigure.SpringBootApplication;
         | 
|  | |
| 12 |  | 
| 13 | 
             
            import java.io.IOException;
         | 
| 14 | 
             
            import java.text.MessageFormat;
         | 
| 15 | 
            +
            import java.util.Collections;
         | 
| 16 | 
             
            import java.util.Enumeration;
         | 
| 17 | 
            +
            import java.util.List;
         | 
| 18 | 
            +
            import java.util.StringTokenizer;
         | 
| 19 |  | 
| 20 | 
             
            @SpringBootApplication
         | 
| 21 | 
             
            public class LearnSpringWebsocketsApplication {
         | 
|  | |
| 30 | 
             
                    @Override
         | 
| 31 | 
             
                    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
         | 
| 32 | 
             
                            throws ServletException, IOException {
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                        final HttpServletRequestWrapper reqWrapper = new HttpServletRequestWrapper(request) {
         | 
| 35 | 
            +
                            @Override
         | 
| 36 | 
            +
                            public Enumeration<String> getHeaders(String name) {
         | 
| 37 | 
            +
                                if ("connection".equals(name) && "UPGRADE".equals(super.getHeaders(name).nextElement())) {
         | 
| 38 | 
            +
                                    return Collections.enumeration(Collections.singleton("Upgrade"));
         | 
| 39 | 
            +
                                }
         | 
| 40 | 
            +
                                return super.getHeaders(name);
         | 
| 41 | 
            +
                            }
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                            @Override
         | 
| 44 | 
            +
                            public String getHeader(String name) {
         | 
| 45 | 
            +
                                if ("connection".equals(name) && "UPGRADE".equals(super.getHeader(name))) {
         | 
| 46 | 
            +
                                    return "Upgrade";
         | 
| 47 | 
            +
                                }
         | 
| 48 | 
            +
                                return super.getHeader(name);
         | 
| 49 | 
             
                            }
         | 
| 50 | 
            +
                        };
         | 
| 51 | 
            +
                        filterChain.doFilter(reqWrapper, response);
         | 
| 52 | 
             
                    }
         | 
| 53 | 
             
                }
         | 
| 54 |  |