File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import (
12
12
"net/http"
13
13
"os"
14
14
"os/signal"
15
+ "time"
15
16
)
16
17
17
18
func ExampleHijacker () {
@@ -221,3 +222,22 @@ func ExampleProtocols_http1or2() {
221
222
}
222
223
res .Body .Close ()
223
224
}
225
+
226
+ func ExampleCrossOriginProtection () {
227
+ mux := http .NewServeMux ()
228
+
229
+ mux .HandleFunc ("/hello" , func (w http.ResponseWriter , req * http.Request ) {
230
+ io .WriteString (w , "request allowed\n " )
231
+ })
232
+
233
+ srv := http.Server {
234
+ Addr : ":8080" ,
235
+ ReadTimeout : 15 * time .Second ,
236
+ WriteTimeout : 15 * time .Second ,
237
+ // Use CrossOriginProtection.Handler to block all non-safe cross-origin
238
+ // browser requests to mux.
239
+ Handler : http .NewCrossOriginProtection ().Handler (mux ),
240
+ }
241
+
242
+ log .Fatal (srv .ListenAndServe ())
243
+ }
You can’t perform that action at this time.
0 commit comments