github.com/apipluspower/gqlgen@v0.15.2/graphql/handler/transport/options.go (about)

     1  package transport
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/apipluspower/gqlgen/graphql"
     7  )
     8  
     9  // Options responds to http OPTIONS and HEAD requests
    10  type Options struct{}
    11  
    12  var _ graphql.Transport = Options{}
    13  
    14  func (o Options) Supports(r *http.Request) bool {
    15  	return r.Method == "HEAD" || r.Method == "OPTIONS"
    16  }
    17  
    18  func (o Options) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor) {
    19  	switch r.Method {
    20  	case http.MethodOptions:
    21  		w.Header().Set("Allow", "OPTIONS, GET, POST")
    22  		w.WriteHeader(http.StatusOK)
    23  	case http.MethodHead:
    24  		w.WriteHeader(http.StatusMethodNotAllowed)
    25  	}
    26  }