shttp

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: Apache-2.0 Imports: 13 Imported by: 5

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.NewRoundTripper(tlsCfg, quicCfg)
}

where tlsCfg and quicCfg can both be left nil.

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 := shttp.ListenAndServe(local, mux)
if err != nil {
	log.Fatal(err)
}

where local is the local (UDP)-address of the server.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(addr string, handler http.Handler) error

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

func MangleSCIONAddrURL

func MangleSCIONAddrURL(url string) string

MangleSCIONAddrURL mangles a SCION address in the host part of a URL-ish string so that it can be safely used as a URL, i.e. it can be parsed by net/url.Parse

func Serve

func Serve(conn net.PacketConn, handler http.Handler) error

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

Types

type RoundTripper

type RoundTripper interface {
	http.RoundTripper
	io.Closer
}

RoundTripper extends the http.RoundTripper interface with a Close

func NewRoundTripper

func NewRoundTripper(tlsClientCfg *tls.Config, quicCfg *quic.Config) RoundTripper

NewRoundTripper creates a new RoundTripper that can be used as the Transport of an http.Client.

type Server

type Server struct {
	*h2quic.Server
}

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 ListenAndServe (instead of Serve) may race if it is called before a UDP socket is established

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

ListenAndServe listens for QUIC connections on srv.Addr and calls Serve to handle incoming requests

func (*Server) Serve

func (srv *Server) Serve(conn net.PacketConn) error

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

Jump to

Keyboard shortcuts

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