github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/igm/sockjs-go.v2/sockjs/web.gon-place (about)

     1  package sockjs
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"time"
     7  )
     8  
     9  func xhrCors(rw http.ResponseWriter, req *http.Request) {
    10  	header := rw.Header()
    11  	origin := req.Header.Get("origin")
    12  	if origin == "" || origin == "null" {
    13  		origin = "*"
    14  	}
    15  	header.Set("Access-Control-Allow-Origin", origin)
    16  
    17  	if allowHeaders := req.Header.Get("Access-Control-Request-Headers"); allowHeaders != "" && allowHeaders != "null" {
    18  		header.Add("Access-Control-Allow-Headers", allowHeaders)
    19  	}
    20  	header.Add("Access-Control-Allow-Credentials", "true")
    21  }
    22  
    23  func xhrOptions(rw http.ResponseWriter, req *http.Request) {
    24  	rw.Header().Set("Access-Control-Allow-Methods", "OPTIONS, POST")
    25  	rw.WriteHeader(http.StatusNoContent) // 204
    26  }
    27  
    28  func cacheFor(rw http.ResponseWriter, req *http.Request) {
    29  	rw.Header().Set("Cache-Control", fmt.Sprintf("public, max-age=%d", 365*24*60*60))
    30  	rw.Header().Set("Expires", time.Now().AddDate(1, 0, 0).Format(time.RFC1123))
    31  	rw.Header().Set("Access-Control-Max-Age", fmt.Sprintf("%d", 365*24*60*60))
    32  }
    33  
    34  func noCache(rw http.ResponseWriter, req *http.Request) {
    35  	rw.Header().Set("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0")
    36  }
    37  
    38  func welcomeHandler(rw http.ResponseWriter, req *http.Request) {
    39  	rw.Header().Set("content-type", "text/plain;charset=UTF-8")
    40  	fmt.Fprintf(rw, "Welcome to SockJS!\n")
    41  }
    42  
    43  func httpError(w http.ResponseWriter, error string, code int) {
    44  	w.Header().Set("Content-Type", "text/plain; charset=utf-8")
    45  	w.WriteHeader(code)
    46  	fmt.Fprintf(w, error)
    47  }