github.com/searKing/golang/go@v1.2.117/net/mux/internal/http2/client_preface.go (about)

     1  // Copyright 2020 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package http2
     6  
     7  import (
     8  	"bytes"
     9  	"io"
    10  
    11  	"golang.org/x/net/http2"
    12  )
    13  
    14  var (
    15  	clientPreface = []byte(http2.ClientPreface)
    16  )
    17  
    18  func HasClientPreface(r io.Reader) bool {
    19  	// Check the validity of client preface.
    20  	preface := make([]byte, len(clientPreface))
    21  	if _, err := io.ReadFull(r, preface); err != nil {
    22  		return false
    23  	}
    24  	return bytes.Equal(preface, clientPreface)
    25  }