在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:google/martian开源软件地址:https://github.com/google/martian开源编程语言:Go 100.0%开源软件介绍:Martian ProxyMartian Proxy is a programmable HTTP proxy designed to be used for testing. Martian is a great tool to use if you want to:
By taking advantage of Go cross-compilation, Martian can be deployed anywhere that Go can target. Latest Versionv3.0.0 RequirementsGo 1.11 Go Modules SupportMartian Proxy added support for Go modules since v3.0.0. If you use a Go version that does not support modules, this will break you. The latest version without Go modules support was tagged v2.1.0. Getting StartedInstallationMartian Proxy can be installed using
Start the ProxyAssuming you've installed Martian, running the proxy is as simple as
If you want to see system logs as Martian is running, pass in the verbosity flag:
By default, Martian will be running on port 8080, and the Martian API will be running on 8181 . The port can be specified via flags:
LoggingFor logging of requests and responses a logging
modifier is
available or HAR logs are
available if the HAR LoggingTo enable HAR logging in Martian call the binary with the
If the
Will retrieve the HAR log of all requests and responses seen by the proxy since the last reset.
Will reset the in-memory HAR log. Note that the log will grow unbounded unless it is periodically reset. ConfigureOnce Martian is running, you need to configure its behavior. Without configuration, Martian is just proxying without doing anything to the requests or responses. If enabled, logging will take place without additional configuration. Martian is configured by JSON messages sent over HTTP that take the general form of:
The above configuration tells Martian to inject a header with the name "Test-Header" and the value "true" on all responses. Let's break down the parts of this message.
This is a simple configuration, for more complex configurations, modifiers are combined with groups and filters to compose the desired behavior. To configure Martian,
Intercepting HTTPS Requests and ResponsesMartian supports modifying HTTPS requests and responses if configured to do so. In order for Martian to intercept HTTPS traffic a custom CA certificate must be installed in the browser so that connection warnings are not shown. The easiest way to install the CA certificate is to start the proxy with the
necessary flags to use a custom CA certificate and private key using the After the proxy has started, visit http://martian.proxy/authority.cer in the browser configured to use the proxy and a prompt will be displayed to install the certificate. Several flags are available in
Check VerifiersLet's assume that you've configured Martian to verify the presence a specific header in responses to a specific URL. Here's a configuration to verify that all requests to
Once Martian is running, configured and the requests and resultant responses you
wish to verify have taken place, you can verify your expectation that you only
got back To check verifications, perform
Failed expectations are tracked as errors, and the list of errors are retrieved
by making a
Verification errors are held in memory until they are explicitly cleared by
Martian as a LibraryMartian can also be included into any Go program and used as a library. Modifiers All The Way DownMartian's request and response modification system is designed to be general and extensible. The design objective is to provide individual modifier behaviors that can arranged to build out nearly any desired modification. When working with Martian to compose behaviors, you'll need to be familiar with these different types of interactions:
Modifiers, filters and groups all implement ModifyRequest(req *http.Request) error
ModifyResponse(res *http.Response) error Throughout the code (and this documentation) you'll see the word "modifier" used as a term that encompasses modifiers, groups and filters. Even though a group does not modify a request or response, we still refer to it as a "modifier". We refer to anything that implements the Parser RegistrationEach modifier must register its own parser with Martian. The parser is responsible for parsing a JSON message into a Go struct that implements a modifier interface. Martian holds modifier parsers as a map of strings to functions that is built
out at run-time. Each modifier is responsible for registering its parser with a
call to Signature of parse.Register: Register(name string, parseFunc func(b []byte) (interface{}, error)) Register takes in the key as a string in the form In the following configuration message,
Example of parser registration from func init() {
parse.Register("header.Modifier", modifierFromJSON)
}
func modifierFromJSON(b []byte) (interface{}, error) {
...
} Adding Your Own ModifierIf you have a use-case in mind that we have not developed modifiers, filters or verifiers for, you can easily extend Martian to your very specific needs. There are 2 mandatory parts of a modifier:
Any Go struct that implements those interfaces can act as a ContactFor questions and comments on how to use Martian, features announcements, or design discussions check out our public Google Group at https://groups.google.com/forum/#!forum/martianproxy-users. For security related issues please send a detailed report to our private core group at [email protected]. DisclaimerThis is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论