shttp

package
v0.0.0-...-42a8572 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

README

HTTP over SCION/QUIC

This package contains a client/server implementation of HTTP/2 over SCION/QUIC.

The Client is a standard net/http client with a custom RoundTripper implementation.

First, create a client:

client := &http.Client{
    Transport: &shttp.Transport{
        LAddr: lAddr,
    },
}

where LAddr is the local SCION address of the client.

Then, make requests as usual:

resp, err := client.Get("http://server:8080/download")

Hostnames are resolved by parsing the /etc/hosts file. Known hosts can be added by adding lines like this:

# The following lines are SCION hosts
17-ffaa:1:10,[10.0.8.100]	host1
18-ffaa:0:11,[10.0.8.120]	host2
The Server is a full HTTP/2 server designed to work similar to the standard net/http implementation. It supports:
  • concurrent handling of clients
  • standard net/http handlers
  • standard net/http helpers such as http.ServeFile, http.Error, http.ServeMux, etc
  • detection of Content-Type and Content-Length and setting of headers accordingly

First, create a ServeMux():

mux := http.NewServeMux()

Then, create handlers:

mux.HandleFunc("/download", func(w http.ResponseWriter, r *http.Request) {
	// Status 200 OK will be set implicitly
	// Content-Length will be inferred by server
	// Content-Type will be detected by server
	http.ServeFile(w, r, "example/sample.html")
})

DefaultServeMux is supported. Use it as usual:

http.HandleFunc("/download", func(w http.ResponseWriter, r *http.Request) {
	// handle request
})

http.Handle("/download", handler)

Finally, start the server:

err := server.ListenAndServeSCION(local, tlsCert, tlsKey, mux)
if err != nil {
	log.Fatal(err)
}

where local is the local address of the server, tlsCert and tlsKey are the TLS key and cert files.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServeSCION

func ListenAndServeSCION(addr, certFile, keyFile string, handler http.Handler) error

ListenAndServeSCION listens for HTTPS connections on the SCION address addr and calls ServeSCION with handler to handle requests

func ServeSCION

func ServeSCION(conn net.PacketConn, handler http.Handler, certFile, keyFile string) error

ServeSCION creates a listener on conn and listens for HTTPS connections. A new goroutine handles each request using handler

Types

type Server

type Server struct {
	Addr string
	// contains filtered or unexported fields
}

Server wraps a h2quic.Server making it work with SCION

func (*Server) Close

func (srv *Server) Close() error

Close the server immediately, aborting requests and sending CONNECTION_CLOSE frames to connected clients Close in combination with ListenAndServeSCION (instead of ServeSCION) may race if it is called before a UDP socket is established

func (*Server) ListenAndServeSCION

func (srv *Server) ListenAndServeSCION(certFile, keyFile string) error

ListenAndServeSCION listens for QUIC connections on srv.Addr and calls ServeSCION to handle incoming requests

func (*Server) ServeSCION

func (srv *Server) ServeSCION(conn net.PacketConn, certFile, keyFile string) error

ServeSCION listens on conn and accepts incoming connections a goroutine is spawned for every request and handled by srv.srv.handler

type Transport

type Transport struct {
	LAddr              *snet.Addr
	QuicConfig         *quic.Config
	DisableCompression bool
	// contains filtered or unexported fields
}

Transport wraps a h2quic.RoundTripper making it compatible with SCION

func (*Transport) Close

func (t *Transport) Close() error

Close closes the QUIC connections that this RoundTripper has used

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip does a single round trip; retreiving a response for a given request

func (*Transport) RoundTripOpt

func (t *Transport) RoundTripOpt(req *http.Request, opt h2quic.RoundTripOpt) (*http.Response, error)

RoundTripOpt is the same as RoundTrip but takes additional options

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL