github.com/alejandroEsc/spdy@v0.0.0-20200317064415-01a02f0eb389/README.md (about)

     1  # Deprecated
     2  
     3  With the release of [Go1.6](https://golang.org/doc/go1.6) and the addition of [http2](https://golang.org/x/net/http2)
     4  to the standard library, this package is no longer under active development. It is highly recommended that former
     5  users of this package migrate to HTTP/2.
     6  
     7  # spdy
     8  
     9  [![GoDoc](https://godoc.org/github.com/SlyMarbo/spdy?status.png)](https://godoc.org/github.com/SlyMarbo/spdy)
    10  
    11  A full-featured SPDY library for the Go language.
    12   
    13  Note that this implementation currently supports SPDY drafts 2 and 3.
    14  
    15  See [these examples][examples] for a quick intro to the package.
    16  
    17  [examples]: https://github.com/SlyMarbo/spdy/tree/master/examples
    18  
    19  Note that using this package with [Martini][martini] is likely to result in strange and hard-to-diagnose
    20  bugs. For more information, read [this article][martini-article]. As a result, issues that arise when
    21  combining the two should be directed at the Martini developers.
    22  
    23  [martini]: https://github.com/go-martini/martini
    24  [martini-article]: http://stephensearles.com/?p=254
    25  
    26  Servers
    27  -------
    28  
    29  
    30  The following examples use features specific to SPDY.
    31  
    32  Just the handler is shown.
    33  
    34  Use SPDY's pinging features to test the connection:
    35  ```go
    36  package main
    37  
    38  import (
    39  	"net/http"
    40  	"time"
    41  
    42  	"github.com/SlyMarbo/spdy"
    43  )
    44  
    45  func Serve(w http.ResponseWriter, r *http.Request) {
    46  	// Ping returns a channel which will send an empty struct.
    47  	if ping, err := spdy.PingClient(w); err == nil {
    48  		select {
    49  		case response := <- ping:
    50  			if response != nil {
    51  				// Connection is fine.
    52  			} else {
    53  				// Something went wrong.
    54  			}
    55  			
    56  		case <-time.After(timeout):
    57  			// Ping took too long.
    58  		}
    59  	} else {
    60  		// Not SPDY
    61  	}
    62  	
    63  	// ...
    64  }
    65  ```
    66  
    67  
    68  
    69  Sending a server push:
    70  ```go
    71  package main
    72  
    73  import (
    74  	"net/http"
    75  	
    76  	"github.com/SlyMarbo/spdy"
    77  )
    78  
    79  func Serve(w http.ResponseWriter, r *http.Request) {
    80  	// Push returns a separate http.ResponseWriter and an error.
    81  	path := r.URL.Scheme + "://" + r.URL.Host + "/example.js"
    82  	push, err := spdy.Push(path)
    83  	if err != nil {
    84  		// Not using SPDY.
    85  	}
    86  	http.ServeFile(push, r, "./content/example.js")
    87  
    88  	// Note that a PushStream must be finished manually once
    89  	// all writing has finished.
    90  	push.Finish()
    91  	
    92  	// ...
    93  }
    94  ```