<logfile>LOCALSTATEDIR/log/gateway.log</logfile>
<loglevel>3</loglevel>
+ <!-- cross origin HTTP settings http://en.wikipedia.org/wiki/Cross-origin_resource_sharing -->
+ <cross_origin>
+ <!-- specify individual hosts -->
+ <!-- <origin>example.com</origin> -->
+ <!-- ...or use the * wildcard to match all -->
+ <!-- <origin>*</origin> -->
+ </cross_origin>
+
</gateway>
<!-- ======================================================================================== -->
return HTTP_INTERNAL_SERVER_ERROR;
}
+int crossOriginHeaders(request_rec* r, osrfStringArray* allowedOrigins) {
+ const char *origin = apr_table_get(r->headers_in, "Origin");
+ if (!origin)
+ return 0;
+
+ /* remove scheme from address */
+ char *host = origin;
+ if ( !strncmp(origin, "http://", 7) )
+ host = origin + 7;
+
+ int found = 0;
+ int i;
+ for ( i = 0; i < allowedOrigins->size; i++ ) {
+ const char* allowedOrigin = osrfStringArrayGetString(allowedOrigins, i);
+ if ( !strcmp(host, allowedOrigin) || !strcmp("*", allowedOrigin) ) {
+ found = 1;
+ break;
+ }
+ }
+
+ if (!found)
+ return 0;
+
+ /* allow CORS response to be cached for 24 hours */
+ apr_table_set(r->headers_out, "Access-Control-Max-Age", "86400");
+ apr_table_set(r->headers_out, "Access-Control-Allow-Credentials", "true");
+ apr_table_set(r->headers_out, "Access-Control-Allow-Origin", origin);
+ apr_table_set(r->headers_out, "Access-Control-Allow-Methods", "POST,OPTIONS");
+ apr_table_set(r->headers_out, "Access-Control-Allow-Headers", OSRF_HTTP_ALL_HEADERS);
+
+ osrfLogInfo(OSRF_LOG_MARK, "Set cross-origin headers for request from %s", origin);
+
+ return 1;
+}
+
+
/* taken more or less directly from O'Reillly - Writing Apache Modules in Perl and C */
/* needs updating...
#endif
#define APACHE_TOOLS_MAX_POST_SIZE 10485760 /* 10 MB */
+#define OSRF_HTTP_ALL_HEADERS "X-OpenSRF-to,X-OpenSRF-xid,X-OpenSRF-from,X-OpenSRF-thread,X-OpenSRF-timeout,X-OpenSRF-service,X-OpenSRF-multipart"
/* parses apache URL params (GET and POST).
*/
int apacheError( char* msg, ... );
+/* Set headers for Cross Origin Resource Sharing requests
+ as per W3 standard http://www.w3.org/TR/cors/ */
+int crossOriginHeaders(request_rec* r, osrfStringArray* allowedOrigins);
+
/*
* Creates an apache table* of cookie name / value pairs
*/
int osrfConnected = 0;
char recipientBuf[128];
char contentTypeBuf[80];
+osrfStringArray* allowedOrigins = NULL;
#if 0
// Commented out to avoid compiler warning
osrfCacheInit(servers, 1, 86400);
osrfConnected = 1;
+ allowedOrigins = osrfNewStringArray(4);
+ osrfConfigGetValueList(NULL, allowedOrigins, "/cross_origin/origin");
+
// at pool destroy time (= child exit time), cleanup
// XXX causes us to disconnect even for clone()'d process cleanup (as in mod_cgi)
//apr_pool_cleanup_register(p, NULL, childExit, apr_pool_cleanup_null);
osrfLogSetAppname("osrf_http_translator");
osrfAppSessionSetIngress(TRANSLATOR_INGRESS);
testConnection(r);
+ crossOriginHeaders(r, allowedOrigins);
osrfLogMkXid();
osrfHttpTranslator* trans = osrfNewHttpTranslator(r);
char* osrf_json_gateway_config_file = NULL;
int bootstrapped = 0;
int numserved = 0;
+osrfStringArray* allowedOrigins = NULL;
static const char* osrf_json_gateway_set_default_locale(cmd_parms *parms,
void *config, const char *arg) {
return;
}
+ allowedOrigins = osrfNewStringArray(4);
+ osrfConfigGetValueList(NULL, allowedOrigins, "/cross_origin/origin");
+
bootstrapped = 1;
osrfLogInfo(OSRF_LOG_MARK, "Bootstrapping gateway child for requests");
/* make sure we're needed first thing*/
if (strcmp(r->handler, MODULE_NAME )) return DECLINED;
+ crossOriginHeaders(r, allowedOrigins);
osrf_json_gateway_dir_config* dir_conf =
ap_get_module_config(r->per_dir_config, &osrf_json_gateway_module);