This is an automated email from the ASF dual-hosted git repository.

harbs pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new 8e1a44382a Make response headers accessible
8e1a44382a is described below

commit 8e1a44382ad30a41627c9d67ad555062b8a52701
Author: Harbs <[email protected]>
AuthorDate: Thu Dec 21 02:10:06 2023 +0200

    Make response headers accessible
---
 .../org/apache/royale/net/URLBinaryLoader.as       | 208 +++++++++++----------
 .../main/royale/org/apache/royale/net/URLStream.as |  38 +++-
 2 files changed, 145 insertions(+), 101 deletions(-)

diff --git 
a/frameworks/projects/Network/src/main/royale/org/apache/royale/net/URLBinaryLoader.as
 
b/frameworks/projects/Network/src/main/royale/org/apache/royale/net/URLBinaryLoader.as
index 24423f2110..80f9ebc941 100644
--- 
a/frameworks/projects/Network/src/main/royale/org/apache/royale/net/URLBinaryLoader.as
+++ 
b/frameworks/projects/Network/src/main/royale/org/apache/royale/net/URLBinaryLoader.as
@@ -17,14 +17,13 @@
 //
 
////////////////////////////////////////////////////////////////////////////////
 package org.apache.royale.net
-{    
-    
-    import org.apache.royale.events.DetailEvent;
-    import org.apache.royale.events.Event;
-    import org.apache.royale.events.ProgressEvent;
-    import org.apache.royale.utils.BinaryData;
-    import org.apache.royale.utils.Endian;
+{
 
+       import org.apache.royale.events.DetailEvent;
+       import org.apache.royale.events.Event;
+       import org.apache.royale.events.ProgressEvent;
+       import org.apache.royale.utils.BinaryData;
+       import org.apache.royale.utils.Endian;
 
        /**
         *  The URLBinaryLoader class is a relatively low-level class designed 
to get
@@ -35,9 +34,8 @@ package org.apache.royale.net
         *  @playerversion AIR 2.6
         *  @productversion Royale 0.7.0
         */
-   public class URLBinaryLoader extends URLLoaderBase
-    {
-        
+       public class URLBinaryLoader extends URLLoaderBase
+       {
           /**
                *  The binary result of the request.
                *  
@@ -45,13 +43,13 @@ package org.apache.royale.net
                *  @playerversion Flash 10.2
                *  @playerversion AIR 2.6
                *  @productversion Royale 0.7.0
-        * 
-        *  @royalesuppresspublicvarwarning
-               */        
+               * 
+               *  @royalesuppresspublicvarwarning
+               */
         public var data:BinaryData;
 
-        private var _endian:String = Endian.BIG_ENDIAN;
-        
+               private var _endian:String = Endian.BIG_ENDIAN;
+
                /**
                 *  Indicates the byte order for the data.
                 *  
@@ -59,19 +57,18 @@ package org.apache.royale.net
                 *  @playerversion Flash 10.2
                 *  @playerversion AIR 2.6
                 *  @productversion Royale 0.7.0
-                */        
-        public function get endian():String
-        {
-            return _endian;
-        }
-        public function set endian(value:String):void
-        {
-            _endian = value;
-        }
+                */
+               public function get endian():String
+               {
+                       return _endian;
+               }
+               public function set endian(value:String):void
+               {
+                       _endian = value;
+               }
 
+               protected var stream:URLStream;
 
-        protected var stream:URLStream;
-        
                /**
                 *  The number of bytes loaded so far.
                 *  
@@ -79,11 +76,11 @@ package org.apache.royale.net
                 *  @playerversion Flash 10.2
                 *  @playerversion AIR 2.6
                 *  @productversion Royale 0.7.0
-         * 
-         *  @royalesuppresspublicvarwarning
-                */        
-        public var bytesLoaded:uint = 0;
-        
+                * 
+                *  @royalesuppresspublicvarwarning
+                */
+               public var bytesLoaded:uint = 0;
+
                /**
                 *  The total number of bytes (if available).
                 *  
@@ -91,63 +88,63 @@ package org.apache.royale.net
                 *  @playerversion Flash 10.2
                 *  @playerversion AIR 2.6
                 *  @productversion Royale 0.7.0
-         * 
-         *  @royalesuppresspublicvarwarning
-                */        
-        public var bytesTotal:uint = 0;
-        
-        public function URLBinaryLoader()
-        {
-            super();
-            createStream();
-        }
-        protected function createStream():void
-        {
-            stream = new URLStream();
-        }
-        private function progressFunction(stream:URLStream):void
-        {
-            bytesLoaded = stream.bytesLoaded;
-            bytesTotal = stream.bytesTotal;
-            dispatchEvent(new 
ProgressEvent("progress",false,false,bytesLoaded,bytesTotal));
-            if(onProgress)
-                onProgress(this);
-        }
-        
-        private function statusFunction(stream:URLStream):void
-        {
-            requestStatus = stream.requestStatus;
-            dispatchEvent(new 
DetailEvent("httpStatus",false,false,""+requestStatus));
-            if(onStatus)
-                onStatus(this);
-        }
-        
-        private function errorFunction(stream:URLStream):void
-        {
+                * 
+                *  @royalesuppresspublicvarwarning
+                */
+               public var bytesTotal:uint = 0;
+               
+               public function URLBinaryLoader()
+               {
+                       super();
+                       createStream();
+               }
+               protected function createStream():void
+               {
+                       stream = new URLStream();
+               }
+               private function progressFunction(stream:URLStream):void
+               {
+                       bytesLoaded = stream.bytesLoaded;
+                       bytesTotal = stream.bytesTotal;
+                       dispatchEvent(new 
ProgressEvent("progress",false,false,bytesLoaded,bytesTotal));
+                       if(onProgress)
+                               onProgress(this);
+               }
+
+               private function statusFunction(stream:URLStream):void
+               {
+                       requestStatus = stream.requestStatus;
+                       dispatchEvent(new 
DetailEvent("httpStatus",false,false,""+requestStatus));
+                       if(onStatus)
+                               onStatus(this);
+               }
+
+               private function errorFunction(stream:URLStream):void
+               {
                        data = stream.response;
-            dispatchEvent(new 
DetailEvent("communicationError",false,false,""+requestStatus));
-            if(onError)
-                onError(this);
-            cleanupCallbacks();
-        }
-        
-        private function completeFunction(stream:URLStream):void
-        {
+                       dispatchEvent(new 
DetailEvent("communicationError",false,false,""+requestStatus));
+                       if(onError)
+                               onError(this);
+                       cleanupCallbacks();
+               }
+
+               private function completeFunction(stream:URLStream):void
+               {
                        data = stream.response;
-            dispatchEvent(new org.apache.royale.events.Event("complete"));
-            if(onComplete)
-                onComplete(this);
-            cleanupCallbacks();
-        }
-        
-        protected function setupCallbacks():void
-        {
-            stream.onProgress = progressFunction;
+                       dispatchEvent(new 
org.apache.royale.events.Event("complete"));
+                       if(onComplete)
+                               onComplete(this);
+                       cleanupCallbacks();
+               }
 
-            stream.onStatus = statusFunction;
-            stream.onError = errorFunction;
-            stream.onComplete = completeFunction;
-        }
+               protected function setupCallbacks():void
+               {
+                       stream.onProgress = progressFunction;
+
+                       stream.onStatus = statusFunction;
+                       stream.onError = errorFunction;
+                       stream.onComplete = completeFunction;
+               }
                /**
                 *  Makes the URL request.
                 *  
@@ -155,13 +152,13 @@ package org.apache.royale.net
                 *  @playerversion Flash 10.2
                 *  @playerversion AIR 2.6
                 *  @productversion Royale 0.7.0
-                */        
-        public function load(request:URLRequest):void
-        {
-            setupCallbacks();
-            stream.load(request);
-        }
-        
+                */
+               public function load(request:URLRequest):void
+               {
+                       setupCallbacks();
+                       stream.load(request);
+               }
+               
                /**
                 *  Cancels the URL request.
                 *  
@@ -169,13 +166,26 @@ package org.apache.royale.net
                 *  @playerversion Flash 10.2
                 *  @playerversion AIR 2.6
                 *  @productversion Royale 0.7.0
-                */        
-        public function close():void
-        {
-            stream.close();
-            cleanupCallbacks();
+                */
+               public function close():void
+               {
+                       stream.close();
+                       cleanupCallbacks();
                        //TODO do we need a callback for canceling?
-        }
-    }
+               }
+               /**
+                * Returns the string value of a specific response header.
+                * The header name is case-insensitive.
+                * 
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.11
+                */
+               public function getResponseHeader(name:String):String
+               {
+                       return stream.getResponseHeader(name);
+               }
+       }
 }
 
diff --git 
a/frameworks/projects/Network/src/main/royale/org/apache/royale/net/URLStream.as
 
b/frameworks/projects/Network/src/main/royale/org/apache/royale/net/URLStream.as
index c6485d319b..550e139f3a 100644
--- 
a/frameworks/projects/Network/src/main/royale/org/apache/royale/net/URLStream.as
+++ 
b/frameworks/projects/Network/src/main/royale/org/apache/royale/net/URLStream.as
@@ -17,7 +17,7 @@
 //
 
////////////////////////////////////////////////////////////////////////////////
 package org.apache.royale.net
-{   
+{
        import org.apache.royale.events.DetailEvent;
        import org.apache.royale.events.Event;
        import org.apache.royale.events.EventDispatcher;
@@ -221,6 +221,34 @@ package org.apache.royale.net
                        }
                }
 
+               /**
+                * Returns the string value of a specific response header.
+                * The header name is case-insensitive.
+                * 
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.11
+                */
+               public function getResponseHeader(header:String):String
+               {
+                       COMPILE::SWF
+                       {
+                               if(flash_headers)
+                               {
+                                       for each(var 
h:flash.net.URLRequestHeader in flash_headers)
+                                       {
+                                               if(h.name.toLowerCase() == 
header.toLowerCase())
+                                                       return h.value;
+                                       }
+                               }
+                               return null;
+                       }
+                       COMPILE::JS
+                       {
+                               return xhr.getResponseHeader(header);
+                       }
+               }
                COMPILE::JS
                protected function createXmlHttpRequest():void
                {
@@ -248,9 +276,15 @@ package org.apache.royale.net
                COMPILE::SWF
                private function flash_status(event:HTTPStatusEvent):void
                {
+                       if(event.responseHeaders)
+                               flash_headers = event.responseHeaders;
+                       
                        setStatus(event.status);
                }
 
+               COMPILE::SWF
+               private var flash_headers:Array;
+
                /**
                 *  IO error occurred (Flash only).
                 *
@@ -562,6 +596,6 @@ package org.apache.royale.net
                        onStatus = callback;
                        return this;
                }
-}
+       }
 }
 

Reply via email to