github.com/richardwilkes/toolbox@v1.121.0/xio/network/xhttp/utility.go (about)

     1  // Copyright (c) 2016-2024 by Richard A. Wilkes. All rights reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the Mozilla Public
     4  // License, version 2.0. If a copy of the MPL was not distributed with
     5  // this file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6  //
     7  // This Source Code Form is "Incompatible With Secondary Licenses", as
     8  // defined by the Mozilla Public License, version 2.0.
     9  
    10  package xhttp
    11  
    12  import "net/http"
    13  
    14  // ErrorStatus sends an HTTP response header with 'statusCode' and follows it with the standard text for that code as
    15  // the body.
    16  func ErrorStatus(w http.ResponseWriter, statusCode int) {
    17  	http.Error(w, http.StatusText(statusCode), statusCode)
    18  }
    19  
    20  // DisableCaching disables caching for the given response writer. To be effective, should be called before any data is
    21  // written.
    22  func DisableCaching(w http.ResponseWriter) {
    23  	header := w.Header()
    24  	header.Set("Cache-Control", "no-store")
    25  	header.Set("Pragma", "no-cache")
    26  }