Skip to content

Commit

Permalink
Removed support/http/server package files
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekn committed Jun 14, 2018
1 parent 79ac06e commit ba7acef
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 39 deletions.
6 changes: 3 additions & 3 deletions services/bridge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/stellar/go/services/bridge/internal/submitter"
supportConfig "github.com/stellar/go/support/config"
"github.com/stellar/go/support/errors"
"github.com/stellar/go/support/http/server"
supportHttp "github.com/stellar/go/support/http"
"github.com/zenazn/goji/graceful"
"github.com/zenazn/goji/web"
"github.com/zenazn/goji/web/middleware"
Expand Down Expand Up @@ -243,8 +243,8 @@ func (a *App) Serve() {
// Middlewares
var headers http.Header
headers.Set("Content-Type", "application/json")
bridge.Use(server.StripTrailingSlashMiddleware("/admin"))
bridge.Use(server.HeadersMiddleware(headers, "/admin/"))
bridge.Use(supportHttp.StripTrailingSlashMiddleware("/admin"))
bridge.Use(supportHttp.HeadersMiddleware(headers, "/admin/"))

if a.config.APIKey != "" {
bridge.Use(apiKeyMiddleware(a.config.APIKey))
Expand Down
10 changes: 5 additions & 5 deletions services/compliance/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/stellar/go/services/compliance/internal/handlers"
supportConfig "github.com/stellar/go/support/config"
"github.com/stellar/go/support/errors"
"github.com/stellar/go/support/http/server"
supportHttp "github.com/stellar/go/support/http"
"github.com/zenazn/goji/graceful"
"github.com/zenazn/goji/web"
)
Expand Down Expand Up @@ -172,8 +172,8 @@ func (a *App) Serve() {
var headers http.Header
headers.Set("Content-Type", "application/json")

external.Use(server.StripTrailingSlashMiddleware())
external.Use(server.HeadersMiddleware(headers))
external.Use(supportHttp.StripTrailingSlashMiddleware())
external.Use(supportHttp.HeadersMiddleware(headers))

external.Post("/", a.requestHandler.HandlerAuth)
external.Get("/tx_status", httpauth.SimpleBasicAuth(a.config.TxStatusAuth.Username, a.config.TxStatusAuth.Password)(http.HandlerFunc(a.requestHandler.HandlerTxStatus)))
Expand All @@ -200,8 +200,8 @@ func (a *App) Serve() {
// Internal endpoints
internal := web.New()

internal.Use(server.StripTrailingSlashMiddleware("/admin"))
internal.Use(server.HeadersMiddleware(headers, "/admin/"))
internal.Use(supportHttp.StripTrailingSlashMiddleware("/admin"))
internal.Use(supportHttp.HeadersMiddleware(headers, "/admin/"))

internal.Post("/send", a.requestHandler.HandlerSend)
internal.Post("/receive", a.requestHandler.HandlerReceive)
Expand Down
25 changes: 25 additions & 0 deletions support/http/headers_middleware.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package http

import (
stdhttp "net/http"
"strings"
)

// HeadersMiddleware sends headers
func HeadersMiddleware(headers stdhttp.Header, ignoredPrefixes ...string) func(next stdhttp.Handler) stdhttp.Handler {
return func(next stdhttp.Handler) stdhttp.Handler {
fn := func(w stdhttp.ResponseWriter, r *stdhttp.Request) {
// Do not change ignored prefixes
for _, prefix := range ignoredPrefixes {
if strings.HasPrefix(r.URL.Path, prefix) {
next.ServeHTTP(w, r)
return
}
}

headers.Write(w)
next.ServeHTTP(w, r)
}
return stdhttp.HandlerFunc(fn)
}
}
25 changes: 0 additions & 25 deletions support/http/server/middleware_headers.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package server
package http

import (
"net/http"
stdhttp "net/http"
"strings"
)

// StripTrailingSlashMiddleware strips trailing slash.
func StripTrailingSlashMiddleware(ignoredPrefixes ...string) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
func StripTrailingSlashMiddleware(ignoredPrefixes ...string) func(next stdhttp.Handler) stdhttp.Handler {
return func(next stdhttp.Handler) stdhttp.Handler {
fn := func(w stdhttp.ResponseWriter, r *stdhttp.Request) {
path := r.URL.Path

// Do not change ignored prefixes
Expand All @@ -29,6 +29,6 @@ func StripTrailingSlashMiddleware(ignoredPrefixes ...string) func(next http.Hand

next.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
return stdhttp.HandlerFunc(fn)
}
}

0 comments on commit ba7acef

Please sign in to comment.