-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add matching for headers and body
- Loading branch information
1 parent
67fbe65
commit 80bb47e
Showing
6 changed files
with
95 additions
and
11 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
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,10 @@ | ||
package matcher | ||
|
||
import "strings" | ||
|
||
func matchContents(body []byte, criteria MatchCriteria) (bool, string) { | ||
if criteria.BodyContains != "" && !strings.Contains(string(body), criteria.BodyContains) { | ||
return false, "body content mismatch" | ||
} | ||
return true, "body content matches" | ||
} |
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,36 @@ | ||
package matcher | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"net/http" | ||
"log" | ||
) | ||
|
||
func matchHeaders(resp *http.Response, criteria MatchCriteria) (bool, string) { | ||
for key, value := range criteria.Headers { | ||
if resp.Header.Get(key) != value { | ||
return false, fmt.Sprintf("header mismatch: %s=%s", key, value) | ||
} | ||
} | ||
return true, "headers match" | ||
} | ||
|
||
func parseHeaders(headersList string) map[string]string { | ||
if headersList == "" { | ||
return nil | ||
} | ||
|
||
headers := make(map[string]string) | ||
headerPairs := strings.Split(headersList, ",") | ||
|
||
for _, pair := range headerPairs { | ||
parts := strings.SplitN(pair, ":", 2) | ||
if len(parts) == 2 { | ||
headers[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1]) | ||
} else { | ||
log.Printf("[WARN] Invalid header format: %s", pair) | ||
} | ||
} | ||
return headers | ||
} |
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