-
Notifications
You must be signed in to change notification settings - Fork 0
RequestMatcher
The RequestMatcher provides an interface to verify that the incoming HTTP request meets defined expectations. It is usually used by the import controller since the import service shall not be bothered with invalid data nor a HTTP request. There are several checks the RequestMatcher is able to run: * Ip address of requesting server against a defined whitelist or a specific ip address. * Attributes of the HTTP header (e.g. Content-Type) matches a defined regular expression. * The pathInfo matches a defined regular expression. * The name of the requesting host does match a regular expression. * The request method matches the defined one.
Since the RequestMatcher is usually used for a web-service to process incoming data it acts as a web-server returning proper HTTP response codes to tell the requester what is happening. These are: * 200 OK * 400 Bad Request * 415 Unsupported Media Type * 500 Internal Server Error * 501 Not Implemented * 503 Service Unavailable The information on when each of those status will be thrown is described on the Push (web services) page.
To enable the RequestMatcher to verify the HTTP request it needs to be configured (see section Configuration). The following example shows a typical call of the RequestMatcher.
`…
$requestMatcher->matchMethod('post'); $requestMatcher->matchServerVar('text/xml; charset=utf-8'); since it is used in a regexp $requestMatcher->matchMethod('post'); // remember to escape special chars $result = $requestMatcher->matches($request); if (RequestMatcher::HTTP_OK == $result['code']){ // all fine now import the data. } throw new \RuntimeException('Verification of the request failed with Code ('.$result['code'].') indicating: '. $result['msg']);
…`
The RequestMatcher is capable of several tests to verify the request is as expected. The configuration of this verifications is handled by a set of methods provided by the RequestMatcher. Every method providing a ability to configure a test has the prefix match. For Example * matchHost() * matchIpWhitelist() * matchMethod()