Created
April 28, 2014 23:39
-
-
Save dgrijalva/11387122 to your computer and use it in GitHub Desktop.
Setting scheme on http and https server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
"github.com/fitstar/falcore" | |
"github.com/fitstar/falcore/filter" | |
"sync" | |
) | |
func main(){ | |
pipeline := falcore.NewPipeline() | |
spipeline := falcore.NewPipeline() | |
upstream := filter.NewUpstream(filter.NewUpstreamTransport("google.com", 80, 0, nil)) | |
// HTTP | |
pipeline.Upstream.PushBack(&SchemeAdder{"http"}) | |
pipeline.Upstream.PushBack(upstream) | |
// HTTPS | |
pipeline.Upstream.PushBack(&SchemeAdder{"https"}) | |
pipeline.Upstream.PushBack(upstream) | |
wg := new(sync.WaitGroup) | |
wg.Add(2) | |
go func(){ | |
srv := falcore.NewServer(3000, pipeline) | |
fmt.Println(srv.ListenAndServe()) | |
wg.Done() | |
}() | |
go func(){ | |
srv := falcore.NewServer(3001, spipeline) | |
fmt.Println(srv.ListenAndServeTLS("mycertfile", "mykeyfile")) | |
wg.Done() | |
}() | |
wg.Wait() | |
} | |
type SchemeAdder struct{ | |
Scheme string | |
} | |
func (f *SchemeAdder) FilterRequest(req *falcore.Request)*http.Response { | |
req.HttpRequest.URL.Scheme = f.Scheme | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment