Permalink
Browse files

added plain text response for image

due to issues in decoding the json response this alternative approach return the user image as plain text

it's up to debate if it will be used

only merge if christian agrees with it
  • Loading branch information...
1 parent dc43e64 commit d16b775e3d826dcdd4165e16736a392dac1780dd @k0pernikus committed Aug 17, 2012
Showing with 11 additions and 6 deletions.
  1. +11 −6 src/Scavenger/WebserviceBundle/Controller/UserController.php
@@ -189,7 +189,7 @@ public function getUserImageAction($id)
$this->assertUserExists($user);
$image = $user->getImage();
- return $this->handleGetResponse(new Response(), array($image));
+ return $this->handleGetResponse(new Response(), array($image), $type="text/plain");
}
@@ -231,14 +231,19 @@ private function assertUserExists($user)
}
}
- private function handleGetResponse($response, $user)
+ private function handleGetResponse($response, $data, $type = "json")
{
- $this->assertUserExists($user);
-
$response->setStatusCode(200);
- $response->setContent(json_encode($user));
- $response->headers->set('Content-Type', 'application/json');
+ if ($type == "json") {
+ $content = json_encode($data);
+ $response->headers->set('Content-Type', 'application/json');
+ } else {
+ $content = $data[0];
+ $response->headers->set('Content-Type', 'text/plain');
+ }
+
+ $response->setContent($content);
return $response;
}

0 comments on commit d16b775

Please sign in to comment.