Skip to content

Instantly share code, notes, and snippets.

@dgrijalva
Created April 28, 2014 23:39
Show Gist options
  • Save dgrijalva/11387122 to your computer and use it in GitHub Desktop.
Save dgrijalva/11387122 to your computer and use it in GitHub Desktop.
Setting scheme on http and https server
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