Skip to content

Commit

Permalink
クエリを含むURLに対応
Browse files Browse the repository at this point in the history
  • Loading branch information
tanaton committed Aug 23, 2014
1 parent c18e219 commit 301597b
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions salami.go
Expand Up @@ -203,13 +203,15 @@ func loadBalancing(bl []Balance) <-chan Balance {

func (sh *SummaryHandle) ServeHTTP(w http.ResponseWriter, r *http.Request) {
u := strings.TrimLeft(r.URL.Path, "/")
pl := strings.Split(u, "/")
if len(pl) < 2 {
if strings.Index(u, "/") < 0 {
// 異常
badRequest(w)
g_log <- fmt.Sprintf("Message:Path error\tPath:%s", u)
return
}
if r.URL.RawQuery != "" {
u += "?" + r.URL.RawQuery
}
// ホワイトリストの確認
if sh.checkUrlWhiteList(u) == false {
badRequest(w)
Expand All @@ -234,7 +236,7 @@ func (sh *SummaryHandle) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
// この処理に時間がかかる
code, err := sh.httpCopy(pl, lbhost, w, r)
code, err := sh.httpCopy(u, lbhost, w, r)

if err == nil {
g_log <- fmt.Sprintf("Host:%s\tPort:%d\tCode:%d\tPath:%s", lbhost.Host, lbhost.Port, code, u)
Expand Down Expand Up @@ -327,12 +329,15 @@ func redirectPolicy(r *http.Request, _ []*http.Request) (err error) {
}

// TCP接続
func (sh *SummaryHandle) httpCopy(s []string, lbhost Balance, w http.ResponseWriter, r *http.Request) (int, error) {
func (sh *SummaryHandle) httpCopy(u string, lbhost Balance, w http.ResponseWriter, r *http.Request) (int, error) {
if lbhost.Host == "" {
lbhost.Host = s[0]
s = s[1:]
i := strings.Index(u, "/")
if i >= 0 {
lbhost.Host = u[:i]
u = u[i+1:]
}
}
req, err := http.NewRequest(r.Method, fmt.Sprintf("http://%s:%d/%s", lbhost.Host, lbhost.Port, strings.Join(s, "/")), nil)
req, err := http.NewRequest(r.Method, fmt.Sprintf("http://%s:%d/%s", lbhost.Host, lbhost.Port, u), nil)
if err != nil {
return 0, err
}
Expand Down

0 comments on commit 301597b

Please sign in to comment.