public function application_octet_stream_mediatype()
 {
     $this->assertEquals(RestFormat::$UNKNOWN, RestFormat::forMediaType('application/octet-stream'));
 }
예제 #2
0
 /**
  * Process request and handle errors
  * 
  * @param  scriptlet.HttpScriptletRequest request The request
  * @param  scriptlet.HttpScriptletResponse response The response
  */
 public function doProcess($request, $response)
 {
     $url = $request->getURL();
     $type = $this->contentTypeOf($request);
     $accept = new Preference($request->getHeader('Accept', '*/*'));
     $this->cat && $this->cat->info($request->getMethod(), $type ?: '(null)', $url->getURL(), $accept);
     // Iterate over all applicable routes
     $ctx = clone $this->context;
     foreach ($this->router->targetsFor($request->getMethod(), $url->getPath(), $type, $accept) as $target) {
         if ($ctx->process($target, $request, $response)) {
             return;
         }
     }
     // No route
     $response->setStatus(HttpConstants::STATUS_NOT_FOUND);
     $format = $accept->match($this->router->getOutputFormats());
     $response->setContentType($format);
     RestFormat::forMediaType($format)->write($response->getOutputStream(), new Payload(['message' => 'Could not route request to ' . $url->getURL()], ['name' => 'error']));
 }
예제 #3
0
 /**
  * Write response body
  *
  * @param  scriptlet.Response response
  * @param  peer.URL base
  * @param  string format
  */
 protected function writeBody($response, $base, $format)
 {
     $response->flush();
     if (null !== $this->payload) {
         RestFormat::forMediaType($format)->write($response->getOutputStream(), $this->payload);
     }
 }
예제 #4
0
 /**
  * Returns a deserializer
  *
  * @param  string $contentType
  * @return webservices.rest.RestDeserializer
  */
 public function deserializerFor($contentType)
 {
     $mediaType = substr($contentType, 0, strcspn($contentType, ';'));
     if (isset($this->deserializers[$mediaType])) {
         return $this->deserializers[$mediaType];
     } else {
         return RestFormat::forMediaType($mediaType)->deserializer();
     }
 }
예제 #5
0
 public function application_octet_stream_mediatype()
 {
     $this->assertFalse(RestFormat::forMediaType('application/octet-stream')->isHandled());
 }