Giter Club home page Giter Club logo

Comments (9)

Dexus avatar Dexus commented on August 22, 2024 1

A quick implementation:

devsisters/goquic

package main

import (
	"crypto/tls"

	"github.com/go-siris/siris"
	"github.com/go-siris/siris/context"

	"golang.org/x/crypto/acme/autocert"

	"github.com/devsisters/goquic"
)


func main() {

	app := siris.New()

	app.Get("/", func(ctx context.Context) {
		ctx.Writef("Hello from the server")
	})

	app.Get("/mypath", func(ctx context.Context) {
		ctx.Writef("Hello from %s", ctx.Path())
	})

	// Note: It's not needed if the first action is "go app.Run".
	if err := app.Build(); err != nil {
		panic(err)
	}

	var tlsConfig *tls.Config

	autoTLSManager := autocert.Manager{
		Prompt:     autocert.AcceptTOS,
		HostPolicy: autocert.HostWhitelist("example.com"),
		Email:      "[email protected]",
		Cache:      autocert.DirCache("./cert/"),
	}

	tlsConfig = new(tls.Config)
	tlsConfig.GetCertificate = autoTLSManager.GetCertificate

	srv2, _ := goquic.NewServer(":443", "/etc/letsencrypt/live/example.com/fullchain.pem", "/etc/letsencrypt/live/example.com/privkey.pem", 1, app, app, tlsConfig)
	go srv2.ListenAndServe()
	println("Start a server listening on https://example.com:8443")

	app.Run(siris.Addr(":80")) // Block here.
}

lucas-clemente/quic-go/h2quic

package main

import (
	"crypto/tls"
	"net/http"

	"github.com/go-siris/siris"
	"github.com/go-siris/siris/context"
	"github.com/go-siris/siris/core/handlerconv"

	"golang.org/x/crypto/acme/autocert"

	"github.com/lucas-clemente/quic-go/h2quic"
)

var h2qserv *h2quic.Server

func main() {

	app := siris.New()
	
	sirisMiddleware := handlerconv.FromStdWithNext(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
		h2qserv.SetQuicHeaders(w.Header())
		next(w, r) // go to the next route's handler
		return
	})
	app.Use(sirisMiddleware)
	
	app.Get("/", func(ctx context.Context) {
		ctx.Writef("Hello from the server")
	})

	app.Get("/mypath", func(ctx context.Context) {
		ctx.Writef("Hello from %s", ctx.Path())
	})

	// Note: It's not needed if the first action is "go app.Run".
	if err := app.Build(); err != nil {
		panic(err)
	}

	var tlsConfig *tls.Config

	autoTLSManager := autocert.Manager{
		Prompt:     autocert.AcceptTOS,
		HostPolicy: autocert.HostWhitelist("example.com"),
		Email:      "[email protected]",
		Cache:      autocert.DirCache("./cert/"),
	}

	tlsConfig = new(tls.Config)
	tlsConfig.GetCertificate = autoTLSManager.GetCertificate

	// start a secondary server listening on localhost:9090.
	// use "go" keyword for Listen functions if you need to use more than one server at the same app.
	//
	// http://localhost:9090/
	// http://localhost:9090/mypath
	
	srv1 := &http.Server{Addr: ":443", TLSConfig: tlsConfig, Handler: app}
	go srv1.ListenAndServeTLS("/etc/letsencrypt/live/example.com/fullchain.pem", "/etc/letsencrypt/live/example.com/privkey.pem")
	println("Start a server listening on https://example.com:443")

	h2qserv = &h2quic.Server{Server: srv1}
	go h2qserv.ListenAndServeTLS("/etc/letsencrypt/live/example.com/fullchain.pem", "/etc/letsencrypt/live/example.com/privkey.pem")
	println("Start a server listening on https://example.com:443 (QUIC)")
	
	// Note: app.Run is totally optional, we have already built the app with app.Build,
	// you can just make a new http.Server instead.
	// http://localhost:8080/
	// http://localhost:8080/mypath
	app.Run(siris.Addr(":80")) // Block here.
}

Test it with chrome chromeBinary --enable-quic --origin-to-force-quic-on=example.com:443 https://example.com

from siris.

Dexus avatar Dexus commented on August 22, 2024 1

So we need to wait, but i prefer lucas-clemente/quic-go/h2quic because it has the heighest versions.

from siris.

bliuchak avatar bliuchak commented on August 22, 2024

See also:

from siris.

godofdream avatar godofdream commented on August 22, 2024

https://github.com/devsisters/goquic seems outdatet. on the other hand devsisters bases on the quic implementation of chromium.
https://github.com/lucas-clemente/quic-go seems newer and simply implemented, but we don't know how long this repository will be maintained.

from siris.

Dexus avatar Dexus commented on August 22, 2024

from siris.

Dexus avatar Dexus commented on August 22, 2024

i have created 2 feature branches, if someone like to add there a example implementation i'm very happy.

feature/quic-devsisters for https://github.com/devsisters/goquic
feature/quic-lucas-clemente for https://github.com/lucas-clemente/quic-go

from siris.

Dexus avatar Dexus commented on August 22, 2024

only problem i found yet is that the devsisters example only listen to UDP4 and not to the UDP6...

Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode       PID/Program name
tcp        0      0 localhost:mysql         *:*                     LISTEN      mysql      67108       25671/mysqld
tcp        0      0 *:ssh                   *:*                     LISTEN      root       9472        4000/sshd
tcp6       0      0 [::]:https              [::]:*                  LISTEN      root       453150      29226/server-app
tcp6       0      0 [::]:http               [::]:*                  LISTEN      root       454266      29226/server-app
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      root       9474        4000/sshd
udp        0      0 *:https                 *:*                                 root       454268      29226/server-app
udp        0      0 *:bootpc                *:*                                 root       6253        3948/dhclient
udp        0      0 localhost:ntp           *:*                                 root       10336       4038/ntpd
udp        0      0 *:ntp                   *:*                                 root       10332       4038/ntpd
udp6       0      0 localhost:ntp           [::]:*                              root       10340       4038/ntpd
udp6       0      0 [::]:ntp                [::]:*                              root       10329       4038/ntpd

from siris.

godofdream avatar godofdream commented on August 22, 2024

what happens if you listen on [::]:443 ?
EDIT ah ok i've seen the code. It wouldn't change anything

from siris.

Dexus avatar Dexus commented on August 22, 2024

see #59

from siris.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.