This commit starts the refactoring of the gadget rendering implementation to accomeda...
[shindig.git] / php / src / gadgets / servlet / ProxyServlet.php
blob8246ef986f3f24fd34fd69afea67d1688fd33a96
1 <?php
2 /**
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
21 require 'src/common/HttpServlet.php';
22 require 'src/gadgets/GadgetContext.php';
23 require 'src/gadgets/ProxyBase.php';
24 require 'src/gadgets/ProxyHandler.php';
25 require 'src/common/RemoteContentRequest.php';
26 require 'src/common/RemoteContent.php';
27 require 'src/common/Cache.php';
28 require 'src/common/RemoteContentFetcher.php';
30 class ProxyServlet extends HttpServlet {
32 public function doGet() {
33 try {
34 // Make sure the HttpServlet doesn't overwrite our headers
35 $this->noHeaders = true;
36 $context = new GadgetContext('GADGET');
37 $url = (isset($_GET['url']) ? $_GET['url'] : (isset($_POST['url']) ? $_POST['url'] : false));
38 $url = urldecode($url);
39 if (! $url) {
40 header("HTTP/1.0 400 Bad Request", true);
41 echo "<html><body><h1>400 - Missing url parameter</h1></body></html>";
43 $proxyHandler = new ProxyHandler($context);
44 $proxyHandler->fetch($url);
45 } catch (Exception $e) {
46 // catch all exceptions and give a 500 server error
47 header("HTTP/1.0 500 Internal Server Error");
48 echo "<h1>Internal server error</h1><p>" . $e->getMessage() . "</p>";
52 public function doPost() {
53 $this->doGet();