-
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.
feat: proxy can capture request body and headers.
- Loading branch information
1 parent
18db7b1
commit 01dd6ca
Showing
6 changed files
with
92 additions
and
35 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,36 @@ | ||
package proxy | ||
|
||
import ( | ||
"mime" | ||
"regexp" | ||
) | ||
|
||
// textMediaTypes are the media types that are eligible for | ||
// request capture and response rewriting. | ||
var textMediaTypes = []string{ | ||
"text/.+", | ||
"application/javascript", | ||
"application/json", | ||
"application/xml", | ||
"application/x-www-form-urlencoded", | ||
} | ||
|
||
// isTextContentType returns true if the media type is eligible for | ||
// request capture and response rewriting. | ||
func isTextContentType(contentType string) bool { | ||
if contentType == "" { | ||
logger.Warnf("missing content type") | ||
return false | ||
} | ||
mediaType, _, err := mime.ParseMediaType(contentType) | ||
if err != nil { | ||
logger.Warnf("failed to parse content type: %v: %v", contentType, err) | ||
return false | ||
} | ||
for _, rewriteMediaType := range textMediaTypes { | ||
if matched, _ := regexp.MatchString(rewriteMediaType, mediaType); matched { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
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