Skip to content

Instantly share code, notes, and snippets.

@ThomasLocke
Created May 30, 2012 10:45
Show Gist options
  • Save ThomasLocke/2835453 to your computer and use it in GitHub Desktop.
Save ThomasLocke/2835453 to your computer and use it in GitHub Desktop.
CORS header support for Ada Web Server.
From 2f858f81c4dbcbdda2cecf70153168d0868e9374 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20L=C3=B8cke?= <[email protected]>
Date: Wed, 30 May 2012 12:34:18 +0200
Subject: [PATCH 2/2] Added Cross-Origin Resource Sharing headers.
http://www.w3.org/TR/cors/
---
src/core/aws-messages.ads | 21 +++++++++++++++++++++
src/core/aws-status.adb | 29 +++++++++++++++++++++++++++++
src/core/aws-status.ads | 16 ++++++++++++++++
3 files changed, 66 insertions(+), 0 deletions(-)
diff --git a/src/core/aws-messages.ads b/src/core/aws-messages.ads
index 70e8880..4aa9f69 100644
--- a/src/core/aws-messages.ads
+++ b/src/core/aws-messages.ads
@@ -88,6 +88,13 @@ package AWS.Messages is
TE_Token : constant String := "TE";
User_Agent_Token : constant String := "User-Agent";
+ -- Cross-Origin Resource Sharing request header tokens.
+ Access_Control_Request_Headers_Token : constant String
+ := "Access-Control-Request-Headers";
+ Access_Control_Request_Method_Token : constant String
+ := "Access-Control-Request-Method";
+ Origin_Token : constant String := "Origin";
+
-- Response header tokens RFC 2616
Accept_Ranges_Token : constant String := "Accept-Ranges";
Age_Token : constant String := "Age";
@@ -99,6 +106,20 @@ package AWS.Messages is
Vary_Token : constant String := "Vary";
WWW_Authenticate_Token : constant String := "WWW-Authenticate";
+ -- Cross-Origin Resource Sharing response header tokens
+ Access_Control_Allow_Credentials_Token : constant String
+ := "Access-Control-Allow-Credentials";
+ Access_Control_Allow_Headers_Token : constant String
+ := "Access-Control-Allow-Headers";
+ Access_Control_Allow_Methods_Token : constant String
+ := "Access-Control-Allow-Methods";
+ Access_Control_Allow_Origin_Token : constant String
+ := "Access-Control-Allow-Origin";
+ Access_Control_Expose_Headers_Token : constant String
+ := "Access-Control-Expose-Headers";
+ Access_Control_Max_Age_Token : constant String
+ := "Access-Control-Max-Age";
+
-- Entity header tokens RFC 2616
Allow_Token : constant String := "Allow";
Content_Encoding_Token : constant String := "Content-Encoding";
diff --git a/src/core/aws-status.adb b/src/core/aws-status.adb
index cd39ee2..0edf189 100644
--- a/src/core/aws-status.adb
+++ b/src/core/aws-status.adb
@@ -47,6 +47,26 @@ package body AWS.Status is
return Headers.Get (D.Header, Messages.Accept_Encoding_Token);
end Accept_Encoding;
+ ------------------------------------
+ -- Access_Control_Request_Headers --
+ ------------------------------------
+
+ function Access_Control_Request_Headers (D : Data) return String is
+ begin
+ return Headers.Get
+ (D.Header, Messages.Access_Control_Request_Headers_Token);
+ end Access_Control_Request_Headers;
+
+ -----------------------------------
+ -- Access_Control_Request_Method --
+ -----------------------------------
+
+ function Access_Control_Request_Method (D : Data) return String is
+ begin
+ return Headers.Get
+ (D.Header, Messages.Access_Control_Request_Method_Token);
+ end Access_Control_Request_Method;
+
-----------------
-- Attachments --
-----------------
@@ -500,6 +520,15 @@ package body AWS.Status is
"Boundary", Case_Sensitive => False);
end Multipart_Boundary;
+ ------------
+ -- Origin --
+ ------------
+
+ function Origin (D : Data) return String is
+ begin
+ return Headers.Get (D.Header, Messages.Origin_Token);
+ end Origin;
+
---------------
-- Parameter --
---------------
diff --git a/src/core/aws-status.ads b/src/core/aws-status.ads
index 5268e86..e1a2089 100644
--- a/src/core/aws-status.ads
+++ b/src/core/aws-status.ads
@@ -164,6 +164,22 @@ package AWS.Status is
-- Returns supported by AWS coding preferred by client from the
-- Accept-Coding header.
+ -------------------------------------------
+ -- Cross-Origin Resource Sharing Headers --
+ -------------------------------------------
+
+ function Origin (D : Data) return String;
+ pragma Inline (Origin);
+ -- Get value for "Origin:" header
+
+ function Access_Control_Request_Headers (D : Data) return String;
+ pragma Inline (Access_Control_Request_Headers);
+ -- Get value for "Access-Control-Request-Headers:" header
+
+ function Access_Control_Request_Method (D : Data) return String;
+ pragma Inline (Access_Control_Request_Method);
+ -- Get value for "Access-Control-Request-Method:" header
+
----------------
-- Connection --
----------------
--
1.7.4.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment