github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/apiserver/params/http.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package params
     5  
     6  import (
     7  	"encoding/base64"
     8  	"fmt"
     9  )
    10  
    11  // DigestAlgorithm is one of the values in the IANA registry. See
    12  // RFC 3230 and 5843.
    13  type DigestAlgorithm string
    14  
    15  const (
    16  	// DigestSHA is the HTTP digest algorithm value used in juju's HTTP code.
    17  	DigestSHA256 DigestAlgorithm = "SHA-256"
    18  
    19  	// The values used for content-type in juju's direct HTTP code:
    20  
    21  	// ContentTypeJSON is the HTTP content-type value used for JSON content.
    22  	ContentTypeJSON = "application/json"
    23  
    24  	// ContentTypeRaw is the HTTP content-type value used for raw, unformattedcontent.
    25  	ContentTypeRaw = "application/octet-stream"
    26  
    27  	// ContentTypeJS is the HTTP content-type value used for javascript.
    28  	ContentTypeJS = "application/javascript"
    29  
    30  	// ContentTypeXJS is the outdated HTTP content-type value used for javascript.
    31  	ContentTypeXJS = "application/x-javascript"
    32  )
    33  
    34  // EncodeChecksum base64 encodes a sha256 checksum according to RFC 4648 and
    35  // returns a value that can be added to the "Digest" http header.
    36  func EncodeChecksum(checksum string) string {
    37  	return fmt.Sprintf("%s=%s", DigestSHA256, base64.StdEncoding.EncodeToString([]byte(checksum)))
    38  }