-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
142 additions
and
62 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package contracts | ||
|
||
import "net/http" | ||
import ( | ||
"net/http" | ||
) | ||
|
||
type Logger interface { | ||
Error(a ...interface{}) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package contracts | ||
|
||
import ( | ||
"net/url" | ||
|
||
"github.com/evg4b/uncors/internal/urlreplacer" | ||
) | ||
|
||
type URLReplacerFactory interface { | ||
Make(requestURL *url.URL) (*urlreplacer.Replacer, *urlreplacer.Replacer, error) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package helpers | ||
|
||
import "strings" | ||
|
||
func AssertIsDefined(value interface{}, message ...string) { | ||
if value == nil { | ||
message := strings.Join(message, " ") | ||
if len(message) == 0 { | ||
message = "Requared variable is not defined" | ||
} | ||
panic(message) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package helpers_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/evg4b/uncors/internal/helpers" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAssertIsDefined(t *testing.T) { | ||
t.Run("where value is nil", func(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
message []string | ||
expected string | ||
}{ | ||
{ | ||
name: "shiuld panic with default message where message is not set", | ||
message: []string{}, | ||
expected: "Requared variable is not defined", | ||
}, | ||
{ | ||
name: "shiuld panic with custom message where it is set", | ||
message: []string{"Cusom message"}, | ||
expected: "Cusom message", | ||
}, | ||
{ | ||
name: "shiuld panic with concatanetion of all passed messages", | ||
message: []string{"This", "is", "custom", "message"}, | ||
expected: "This is custom message", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.PanicsWithValue(t, tt.expected, func() { | ||
helpers.AssertIsDefined(nil, tt.message...) | ||
}) | ||
}) | ||
} | ||
}) | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package proxy | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
func (handler *Handler) makeOptionsResponse(writer http.ResponseWriter, req *http.Request) error { | ||
header := writer.Header() | ||
for key, values := range req.Header { | ||
lowerKey := strings.ToLower(key) | ||
if strings.Contains(lowerKey, "access-control-request") { | ||
for _, value := range values { | ||
transformedKey := strings.Replace(lowerKey, "request", "allow", 1) | ||
header.Add(transformedKey, value) | ||
} | ||
} | ||
} | ||
|
||
handler.logger.PrintResponse(&http.Response{ | ||
StatusCode: http.StatusOK, | ||
Request: req, | ||
}) | ||
|
||
return nil | ||
} |
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
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
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
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