shttp

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2020 License: Apache-2.0 Imports: 12 Imported by: 5

README

HTTP over SCION/QUIC

This package contains a client/server implementation of HTTP/3 over SCION/QUIC as well as a proxy implementation to proxy HTTP/3 requests over SCION to HTTP/1.1 and vice versa.

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 or by a RAINS lookup (see Hostnames).

The Server is a full HTTP/3 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, nil)
if err != nil {
	log.Fatal(err)
}

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

Proxy combines the client and server implementation

The proxy can handle two directions: From HTTP/1.1 to SCION and from SCION to HTTP/1.1. Its idea is to make resources provided over HTTP accessible over the SCION network.

To use the proxy, consider the proxy example in _examples. This implementation detects from the format of the remote and local argument if it should listen on SCION/HTTP/1.1 and proxy to SCION/HTTP/1.1.

Example code can be found here: _examples/shttp/proxy

To proxy from SCION to HTTP/1.1, use ./proxy --local="19-ffcc:1:aaa,[127.0.0.1]:42424" --remote="http://192.168.0.1:8090"

and to proxy to SCION from HTTP/1.1, use ./proxy --remote="19-ffcc:1:aaa,[127.0.0.1]:42425" --local="192.168.0.1:8091"

Furthermore, also proxying from SCION to SCION and from HTTP/1.1 to HTTP/1.1 is possible by entering the correct address formats for SCION and HTTP/1.1 respectively.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(addr string, handler http.Handler, tlsConfig *tls.Config) 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 NewSingleSCIONHostReverseProxy added in v0.2.0

func NewSingleSCIONHostReverseProxy(remote string, cliTLSCfg *tls.Config) (*httputil.ReverseProxy, error)

Proxies the incoming HTTP/1.1 request to the configured remote creating a new SCION HTTP/3 request

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 {
	*http3.Server
}

Server wraps a http3.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