github.com/alejandroesc/spdy@v0.0.0-20200317064415-01a02f0eb389/doc.go (about)

     1  // Copyright 2013 Jamie Hall. 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  /*
     6  Package spdy is a full-featured SPDY library for the Go language (still under very active development).
     7  
     8  Note that this implementation currently supports SPDY drafts 2 and 3, and support for SPDY/4, and HTTP/2.0 is upcoming.
     9  
    10  See examples for various simple examples that use the package.
    11  
    12  -------------------------------
    13  
    14  Note that using this package with Martini (https://github.com/go-martini/martini) is likely to result
    15  in strange and hard-to-diagnose bugs. For more information, read http://stephensearles.com/?p=254.
    16  As a result, issues that arise when combining the two should be directed at the Martini developers.
    17  
    18  -------------------------------
    19  
    20  		Servers
    21  
    22  The following examples use features specific to SPDY.
    23  
    24  Just the handler is shown.
    25  
    26  Use SPDY's pinging features to test the connection:
    27  
    28  		package main
    29  
    30  		import (
    31  			"net/http"
    32  			"time"
    33  
    34  			"github.com/SlyMarbo/spdy"
    35  		)
    36  
    37  		func Serve(w http.ResponseWriter, r *http.Request) {
    38  			// Ping returns a channel which will send a bool.
    39  			if ping, err := spdy.PingClient(w); err == nil {
    40  				select {
    41  				case _, ok := <- ping:
    42  					if ok {
    43  						// Connection is fine.
    44  					} else {
    45  						// Something went wrong.
    46  					}
    47  
    48  				case <-time.After(timeout):
    49  					// Ping took too long.
    50  				}
    51  			} else {
    52  				// Not SPDY.
    53  			}
    54  
    55  			// ...
    56  		}
    57  
    58  
    59  Sending a server push:
    60  
    61  		package main
    62  
    63  		import (
    64  			"net/http"
    65  
    66  			"github.com/SlyMarbo/spdy"
    67  		)
    68  
    69  		func Serve(w http.ResponseWriter, r *http.Request) {
    70  			// Push returns a separate http.ResponseWriter and an error.
    71  			path := r.URL.Scheme + "://" + r.URL.Host + "/example.js"
    72  			push, err := spdy.Push(path)
    73  			if err != nil {
    74  				// Not using SPDY.
    75  			}
    76  			http.ServeFile(push, r, "./content/example.js")
    77  
    78  			// Note that a PushStream must be finished manually once
    79  			// all writing has finished.
    80  			push.Finish()
    81  
    82  			// ...
    83  		}
    84  
    85  */
    86  package spdy