mirror of
https://github.com/caddyserver/caddy.git
synced 2026-05-24 00:19:53 -04:00
* Fixed issue with {path} actually {uri}
* Test added for path rewrite
* add in uri_escaped
* added rewrite_uri and test
* fix broken test. Just checks for existance of rewrite header
* gitignore
* Use context to store uri value
* ignore .vscode
* tidy up, removal of comments and invalidated tests
* Remove commented out code.
* added comment as requested by lint
* fixed spelling mistake
* clarified code with variable name
* added context for uri and test
* added TODO comment to move consts
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
package httpserver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/mholt/caddy"
|
||||
)
|
||||
|
||||
func TestNewReplacer(t *testing.T) {
|
||||
@@ -149,6 +152,40 @@ func TestSet(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test function to test that various placeholders hold correct values after a rewrite
|
||||
// has been performed. The NewRequest actually contains the rewritten value.
|
||||
func TestPathRewrite(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
recordRequest := NewResponseRecorder(w)
|
||||
reader := strings.NewReader(`{"username": "dennis"}`)
|
||||
|
||||
request, err := http.NewRequest("POST", "http://getcaddy.com/index.php?key=value", reader)
|
||||
if err != nil {
|
||||
t.Fatalf("Request Formation Failed: %s\n", err.Error())
|
||||
}
|
||||
|
||||
ctx := context.WithValue(request.Context(), caddy.URIxRewriteCtxKey, "a/custom/path.php?key=value")
|
||||
request = request.WithContext(ctx)
|
||||
|
||||
repl := NewReplacer(request, recordRequest, "")
|
||||
|
||||
if repl.Replace("This path is '{path}'") != "This path is 'a/custom/path.php'" {
|
||||
t.Error("Expected host {path} replacement failed (" + repl.Replace("This path is '{path}'") + ")")
|
||||
}
|
||||
|
||||
if repl.Replace("This path is {rewrite_path}") != "This path is /index.php" {
|
||||
t.Error("Expected host {rewrite_path} replacement failed (" + repl.Replace("This path is {rewrite_path}") + ")")
|
||||
}
|
||||
if repl.Replace("This path is '{uri}'") != "This path is 'a/custom/path.php?key=value'" {
|
||||
t.Error("Expected host {uri} replacement failed (" + repl.Replace("This path is '{uri}'") + ")")
|
||||
}
|
||||
|
||||
if repl.Replace("This path is {rewrite_uri}") != "This path is /index.php?key=value" {
|
||||
t.Error("Expected host {rewrite_uri} replacement failed (" + repl.Replace("This path is {rewrite_uri}") + ")")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestRound(t *testing.T) {
|
||||
var tests = map[time.Duration]time.Duration{
|
||||
// 599.935µs -> 560µs
|
||||
|
||||
Reference in New Issue
Block a user