@@ -45,12 +45,6 @@ func main() {
4545
4646 if path .Passthrough {
4747 router .PathPrefix (path .Path ).HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
48- if r .Method == http .MethodOptions {
49- w .Header ().Add ("Methods" , "OPTIONS, GET, HEAD" )
50- writeError (w , http .StatusOK , "options response from filter-proxy" )
51- return
52- }
53-
5448 client := & http.Client {}
5549
5650 //http: Request.RequestURI can't be set in client requests.
@@ -105,12 +99,6 @@ func main() {
10599 return
106100 }
107101
108- if r .Method == http .MethodOptions {
109- w .Header ().Add ("Methods" , "OPTIONS, GET, HEAD" )
110- writeError (w , http .StatusOK , "options response from filter-proxy" )
111- return
112- }
113-
114102 utils .DelHopHeaders (r .Header )
115103
116104 var bodyFilterParams map [string ]interface {}
@@ -309,24 +297,42 @@ func main() {
309297 }
310298 }
311299
312- var httpHandler http.Handler
300+ // By default allow only https://filter-proxy.local
301+ corsOptions := cors.Options {
302+ AllowedOrigins : []string {
303+ "https://filter-proxy.local" ,
304+ },
305+ Debug : config .Cors .DebugLogging ,
306+ OptionsPassthrough : false ,
307+ }
308+
313309 if len (config .Cors .AllowedOrigins ) > 0 {
314- c := cors .New (cors.Options {
315- AllowedOrigins : config .Cors .AllowedOrigins ,
316- AllowedMethods : config .Cors .AllowedMethods ,
317- AllowedHeaders : config .Cors .AllowedHeaders ,
318- AllowCredentials : config .Cors .AllowCredentials ,
319- AllowPrivateNetwork : config .Cors .AllowPrivateNetwork ,
320- })
321-
322- httpHandler = c .Handler (router )
323- } else {
324- httpHandler = router
310+ corsOptions .AllowedOrigins = config .Cors .AllowedOrigins
325311 }
326312
313+ if len (config .Cors .AllowedMethods ) > 0 {
314+ corsOptions .AllowedMethods = config .Cors .AllowedMethods
315+ }
316+
317+ if len (config .Cors .AllowedHeaders ) > 0 {
318+ corsOptions .AllowedHeaders = config .Cors .AllowedHeaders
319+ }
320+
321+ if config .Cors .AllowCredentials {
322+ corsOptions .AllowCredentials = config .Cors .AllowCredentials
323+ }
324+
325+ if config .Cors .AllowPrivateNetwork {
326+ corsOptions .AllowPrivateNetwork = config .Cors .AllowPrivateNetwork
327+ }
328+
329+ c := cors .New (corsOptions )
330+
331+ handler := c .Handler (router )
332+
327333 s := & http.Server {
328334 Addr : config .ListenAddress ,
329- Handler : requestLoggingMiddleware (httpHandler ),
335+ Handler : requestLoggingMiddleware (handler ),
330336 ReadTimeout : 10 * time .Second ,
331337 WriteTimeout : 10 * time .Second ,
332338 MaxHeaderBytes : 1 << 20 ,
0 commit comments