mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-10-31 10:37:24 -04:00 
			
		
		
		
	header: implement http.Hijacker for responseWriterWrapper
fix issue #1173 Signed-off-by: Tw <tw19881113@gmail.com>
This commit is contained in:
		
							parent
							
								
									9ced4b17e5
								
							
						
					
					
						commit
						e5d33e73f3
					
				| @ -4,6 +4,9 @@ | |||||||
| package header | package header | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"bufio" | ||||||
|  | 	"errors" | ||||||
|  | 	"net" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"strings" | 	"strings" | ||||||
| 
 | 
 | ||||||
| @ -113,3 +116,12 @@ func (rww *responseWriterWrapper) setHeader(key, value string) { | |||||||
| 		h.Set(key, value) | 		h.Set(key, value) | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | // Hijack implements http.Hijacker. It simply wraps the underlying | ||||||
|  | // ResponseWriter's Hijack method if there is one, or returns an error. | ||||||
|  | func (rww *responseWriterWrapper) Hijack() (net.Conn, *bufio.ReadWriter, error) { | ||||||
|  | 	if hj, ok := rww.w.(http.Hijacker); ok { | ||||||
|  | 		return hj.Hijack() | ||||||
|  | 	} | ||||||
|  | 	return nil, nil, errors.New("not a Hijacker") | ||||||
|  | } | ||||||
|  | |||||||
| @ -189,7 +189,7 @@ func (rp *ReverseProxy) ServeHTTP(rw http.ResponseWriter, outreq *http.Request, | |||||||
| 		res.Body.Close() | 		res.Body.Close() | ||||||
| 		hj, ok := rw.(http.Hijacker) | 		hj, ok := rw.(http.Hijacker) | ||||||
| 		if !ok { | 		if !ok { | ||||||
| 			return nil | 			panic("not a hijacker") | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		conn, _, err := hj.Hijack() | 		conn, _, err := hj.Hijack() | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user