aboutsummaryrefslogtreecommitdiff
path: root/src/hostlist
diff options
context:
space:
mode:
authorDavid Barksdale <amatus.amongus@gmail.com>2014-05-26 17:23:39 +0000
committerDavid Barksdale <amatus.amongus@gmail.com>2014-05-26 17:23:39 +0000
commit1cfab01aaea932539c39dcb2118ec4d6c6d44381 (patch)
tree81d11aedb53e846dec3b55b132082e87e18f7727 /src/hostlist
parentc6e5027466dbe379d4fad8795ca3a40da5bdb493 (diff)
downloadgnunet-1cfab01aaea932539c39dcb2118ec4d6c6d44381.tar.gz
gnunet-1cfab01aaea932539c39dcb2118ec4d6c6d44381.zip
Add CORS support to hostlist server
Diffstat (limited to 'src/hostlist')
-rw-r--r--src/hostlist/hostlist-server.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c
index 2564991d5..b840eb693 100644
--- a/src/hostlist/hostlist-server.c
+++ b/src/hostlist/hostlist-server.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2008, 2009, 2010 Christian Grothoff (and other contributing authors) 3 (C) 2008, 2009, 2010, 2014 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -20,7 +20,7 @@
20 20
21/** 21/**
22 * @file hostlist/hostlist-server.c 22 * @file hostlist/hostlist-server.c
23 * @author Christian Grothoff, Matthias Wachs 23 * @author Christian Grothoff, Matthias Wachs, David Barksdale
24 * @brief application to provide an integrated hostlist HTTP server 24 * @brief application to provide an integrated hostlist HTTP server
25 */ 25 */
26 26
@@ -250,6 +250,23 @@ accept_policy_callback (void *cls, const struct sockaddr *addr,
250 return MHD_YES; /* accept all */ 250 return MHD_YES; /* accept all */
251} 251}
252 252
253/**
254 * Add headers to a request indicating that we allow Cross-Origin Resource
255 * Sharing.
256 */
257static void
258add_cors_headers(struct MHD_Response *response)
259{
260 MHD_add_response_header (response,
261 "Access-Control-Allow-Origin",
262 "*");
263 MHD_add_response_header (response,
264 "Access-Control-Allow-Methods",
265 "GET, OPTIONS");
266 MHD_add_response_header (response,
267 "Access-Control-Max-Age",
268 "86400");
269}
253 270
254/** 271/**
255 * Main request handler. 272 * Main request handler.
@@ -262,6 +279,19 @@ access_handler_callback (void *cls, struct MHD_Connection *connection,
262{ 279{
263 static int dummy; 280 static int dummy;
264 281
282 /* CORS pre-flight request */
283 if (0 == strcmp (MHD_HTTP_METHOD_OPTIONS, method))
284 {
285 struct MHD_Response *options_response;
286 int rc;
287
288 options_response = MHD_create_response_from_buffer (0, NULL,
289 MHD_RESPMEM_PERSISTENT);
290 add_cors_headers(options_response);
291 rc = MHD_queue_response (connection, MHD_HTTP_OK, options_response);
292 MHD_destroy_response (options_response);
293 return rc;
294 }
265 if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) 295 if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
266 { 296 {
267 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 297 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -303,6 +333,7 @@ access_handler_callback (void *cls, struct MHD_Connection *connection,
303 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received request for our hostlist\n")); 333 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received request for our hostlist\n"));
304 GNUNET_STATISTICS_update (stats, gettext_noop ("hostlist requests processed"), 334 GNUNET_STATISTICS_update (stats, gettext_noop ("hostlist requests processed"),
305 1, GNUNET_YES); 335 1, GNUNET_YES);
336 add_cors_headers(response);
306 return MHD_queue_response (connection, MHD_HTTP_OK, response); 337 return MHD_queue_response (connection, MHD_HTTP_OK, response);
307} 338}
308 339