EchoScript for Map Mock
EchoScript is the core of Map Mock. It can work with both Map Local and Map Remote.
By default, EchoScript code is commented out, which means it does nothing.
Callback functions
EchoScript has two standard callback functions: on_request and on_response, which can be used to modify HTTP(s) request and response respectively.
on_request
The return value of on_request
is a map
, which tells EchoProxy how to modify HTTP(s) request.
Return an empty map {}
means it does nothing.
The structure of on_request return
value. All fields are optional.
on_response
The return value of on_response
is a map
, which tells EchoProxy how to modify HTTP(s) response.
Return an empty map {}
means it does nothing.
The structure of on_response return
value. All fields are optional.
Map modify strategy
When the field
type is a map
, the default modify strategy is to merge
the two maps
.
The other types (string|int|float|file|array
) use assign
strategy, which means the new value overwrite old value.
field type | modify strategy |
---|---|
map | merge |
string | assign overwrite |
int|float | assign overwrite |
file | assign overwrite |
array | assign overwrite |
Merge Example
Let’s take body
field as an example. The original body
value:
The returned body
value:
The final body
value is the merge result of the two maps
:
Assign Example
The original body
value is the same with previous example.
The returned body
value is handled with function assign
:
The final body
value will be the same with the assign
argument:
Function arguments
req
The argument req
represents the incoming HTTP request. The structure of req
:
res
The argument res
represents the response got from remote HTTP request (MapRemote),
or the response loaded from local file (MapLocal). The structure of res
:
env
The argument env
is a map
, which is designed to get and set enviroment variables.
TODO: under development
Example: Pass variable env.key1
from on_request
to on_response
, and print
its value to Log tab.