public override void Fetch(HttpRequestWrapper request, HttpResponseWrapper response) { if (request.getHeaders("If-Modified-Since") != null) { if (!request.isConcat) { response.setStatus((int)HttpStatusCode.NotModified); } return; } String host = request.getHeaders("Host"); if (!lockedDomainService.isSafeForOpenProxy(host)) { // Force embedded images and the like to their own domain to avoid XSS // in gadget domains. return; } sRequest rcr = buildHttpRequest(request); sResponse results = fetcher.fetch(rcr); if (contentRewriterRegistry != null) { results = contentRewriterRegistry.rewriteHttpResponse(rcr, results); } if (!request.isConcat) { SetResponseHeaders(request, response.getResponse(), results); for (int i = 0; i < results.getHeaders().Count; i++) { String name = results.getHeaders().GetKey(i); if (!DISALLOWED_RESPONSE_HEADERS.Contains(name.ToLower())) { foreach (String value in results.getHeaders().GetValues(i)) { response.AddHeader(name, value); } } } } if (request.getParameter("rewriteMime") != null) { response.setContentType(request.getParameter("rewriteMime")); } if (results.getHttpStatusCode() != (int)HttpStatusCode.OK) { response.setStatus((int)results.getHttpStatusCode()); } else { response.setStatus((int)HttpStatusCode.OK); } response.Write(results.responseBytes); }
private static void addHeaders(JsonObject headers, sResponse response, String headerName) { string[] values = response.getHeaders(headerName); if (values != null) { headers.Put(headerName.ToLower(), new JsonArray(values)); } }
/** * Parse OAuth WWW-Authenticate header and either add them to an existing * message or create a new message. * * @param msg * @param resp * @return the updated message. */ private static OAuthMessage parseAuthHeader(OAuthMessage msg, sResponse resp) { if (msg == null) { msg = new OAuthMessage(null, null, null); } foreach (String auth in resp.getHeaders("WWW-Authenticate")) { msg.addParameters(OAuthMessage.decodeAuthorization(auth)); } return(msg); }