flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yish...@apache.org
Subject git commit: [flex-asjs] [refs/heads/refactor-sprite] - Added URLRequestHeader
Date Tue, 23 Aug 2016 11:18:20 GMT
Repository: flex-asjs
Updated Branches:
  refs/heads/refactor-sprite a47e05f14 -> d79ea5e66


Added URLRequestHeader


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/d79ea5e6
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/d79ea5e6
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/d79ea5e6

Branch: refs/heads/refactor-sprite
Commit: d79ea5e66aa1495cf31941bf255d2a36164bf29c
Parents: a47e05f
Author: yishayw <yishayjobs@hotmail.com>
Authored: Tue Aug 23 14:18:10 2016 +0300
Committer: yishayw <yishayjobs@hotmail.com>
Committed: Tue Aug 23 14:18:10 2016 +0300

----------------------------------------------------------------------
 .../flex/org/apache/flex/net/BinaryUploader.as  |  8 +--
 .../flex/org/apache/flex/net/HTTPService.as     |  8 +--
 .../main/flex/org/apache/flex/net/URLRequest.as |  4 +-
 .../org/apache/flex/net/URLRequestHeader.as     | 62 ++++++++++++++++++++
 .../main/flex/org/apache/flex/net/URLStream.as  | 41 +++++++++++--
 5 files changed, 109 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d79ea5e6/frameworks/projects/Network/src/main/flex/org/apache/flex/net/BinaryUploader.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/BinaryUploader.as
b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/BinaryUploader.as
index 3ca3950..035f753 100644
--- a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/BinaryUploader.as
+++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/BinaryUploader.as
@@ -240,12 +240,12 @@ package org.apache.flex.net
             {
                 if (_responseHeaders && _responseHeaders.length > 0)
                 {
-                    if (_responseHeaders[0] is URLRequestHeader)
+                    if (_responseHeaders[0] is flash.net.URLRequestHeader)
                     {
                         var n:int = _responseHeaders.length;
                         for (var i:int = 0; i < n; i++)
                         {
-                            var old:URLRequestHeader = _responseHeaders[i];
+                            var old:flash.net.URLRequestHeader = _responseHeaders[i];
                             var nu:HTTPHeader = new HTTPHeader(old.name, old.value);
                             _responseHeaders[i] = nu;
                         }
@@ -515,7 +515,7 @@ package org.apache.flex.net
                 {
                     for each (var header:HTTPHeader in headers)
                     {
-                        var urlHeader:URLRequestHeader = new URLRequestHeader(header.name,
header.value);
+                        var urlHeader:flash.net.URLRequestHeader = new flash.net.URLRequestHeader(header.name,
header.value);
                         request.requestHeaders.push(urlHeader);
                         if (header.name == HTTPHeader.CONTENT_TYPE)
                             sawContentType = true;
@@ -523,7 +523,7 @@ package org.apache.flex.net
                 }
                 if (method != HTTPConstants.GET && !sawContentType)
                 {
-                    urlHeader = new URLRequestHeader(HTTPHeader.CONTENT_TYPE, contentType);
+                    urlHeader = new flash.net.URLRequestHeader(HTTPHeader.CONTENT_TYPE, contentType);
                     request.requestHeaders.push(urlHeader);
                 }
                 if (binaryData)

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d79ea5e6/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPService.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPService.as
b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPService.as
index d4a5d0d..b72f6c5 100644
--- a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPService.as
+++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPService.as
@@ -246,12 +246,12 @@ package org.apache.flex.net
             {
                 if (_responseHeaders && _responseHeaders.length > 0)
                 {
-                    if (_responseHeaders[0] is URLRequestHeader)
+                    if (_responseHeaders[0] is flash.net.URLRequestHeader)
                     {
                         var n:int = _responseHeaders.length;
                         for (var i:int = 0; i < n; i++)
                         {
-                            var old:URLRequestHeader = _responseHeaders[i];
+                            var old:flash.net.URLRequestHeader = _responseHeaders[i];
                             var nu:HTTPHeader = new HTTPHeader(old.name, old.value);
                             _responseHeaders[i] = nu;
                         }
@@ -528,7 +528,7 @@ package org.apache.flex.net
                 {
                     for each (var header:HTTPHeader in headers)
                     {
-                        var urlHeader:URLRequestHeader = new URLRequestHeader(header.name,
header.value);
+                        var urlHeader:flash.net.URLRequestHeader = new flash.net.URLRequestHeader(header.name,
header.value);
                         request.requestHeaders.push(urlHeader);
                         if (header.name == HTTPHeader.CONTENT_TYPE)
                             sawContentType = true;
@@ -536,7 +536,7 @@ package org.apache.flex.net
                 }
                 if (method != HTTPConstants.GET && !sawContentType && contentData
!= null)
                 {
-                    urlHeader = new URLRequestHeader(HTTPHeader.CONTENT_TYPE, contentType);
+                    urlHeader = new flash.net.URLRequestHeader(HTTPHeader.CONTENT_TYPE, contentType);
                     request.requestHeaders.push(urlHeader);
                 }
                 if (contentData)

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d79ea5e6/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLRequest.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLRequest.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLRequest.as
index c9db327..389531f 100644
--- a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLRequest.as
+++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLRequest.as
@@ -70,6 +70,7 @@ package org.apache.flex.net
 		 *  @productversion FlexJS 0.7.0
 		 */	
 		public var method:String = HTTPConstants.GET;
+		private var _requestHeaders:Array;
         
         public function URLRequest(url:String = null)
         {
@@ -83,11 +84,12 @@ package org.apache.flex.net
         
         public function get requestHeaders():Array
         {
-            return null;
+            return _requestHeaders;
         }
         
         public function set requestHeaders(value:Array) : void
         {
+			_requestHeaders = value;
         }
         
     }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d79ea5e6/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLRequestHeader.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLRequestHeader.as
b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLRequestHeader.as
new file mode 100644
index 0000000..9680764
--- /dev/null
+++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLRequestHeader.as
@@ -0,0 +1,62 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.net
+{
+	/**
+	 *  A URLRequestHeader object represents an HTTP request header.
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion FlexJS 0.7.0
+	 */
+	
+    public class URLRequestHeader
+    {
+		/**
+		 *  An HTTP request header name
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.7.0
+		 */	
+        
+		public var name:String;
+		
+		/**
+		 *  A value of an HTTPRequestHeader
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.7.0
+		 */	
+        public var value:String;
+		
+		
+        
+        public function URLRequestHeader(name:String, value:String)
+        {
+			this.name = name;
+			this.value = value;
+        }
+        
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d79ea5e6/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLStream.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLStream.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLStream.as
index 3949a8c..e100be4 100644
--- a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLStream.as
+++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLStream.as
@@ -18,6 +18,8 @@
 ////////////////////////////////////////////////////////////////////////////////
 package org.apache.flex.net
 {   
+    import flash.utils.clearTimeout;
+    
     import org.apache.flex.events.DetailEvent;
     import org.apache.flex.events.Event;
     import org.apache.flex.events.EventDispatcher;
@@ -99,16 +101,45 @@ package org.apache.flex.net
                 xhr.responseType = "arraybuffer";
                 xhr.addEventListener("readystatechange", xhr_onreadystatechange,false);
                 xhr.addEventListener("progress", xhr_progress, false);
-                xhr.setRequestHeader("Content-type", urlRequest.contentType);
-                xhr.send(HTTPUtils.encodeUrlVariables(urlRequest.data));
+				var contentTypeSet:Boolean = false;
+				for (var i:int = 0; i < urlRequest.requestHeaders.length; i++)
+				{
+					var header:org.apache.flex.net.URLRequestHeader = urlRequest.requestHeaders[i];
+					if (header.name.toLowerCase() == "content-type")
+					{
+						contentTypeSet = true;
+					}
+					xhr.setRequestHeader(header.name, header.value);
+				}
+				if (!contentTypeSet)
+				{
+            		xhr.setRequestHeader("Content-type", urlRequest.contentType);
+				}
+				var requestData:Object = urlRequest.data is BinaryData ? (urlRequest.data as BinaryData).data
: HTTPUtils.encodeUrlVariables(urlRequest.data);
+				xhr.send(requestData);
+//				xhr.send(HTTPUtils.encodeUrlVariables(urlRequest.data));
             }
             COMPILE::SWF 
             {
                 flashUrlStream = new flash.net.URLStream();
                 var req:flash.net.URLRequest = new flash.net.URLRequest(urlRequest.url);
-                var hdr:URLRequestHeader = new URLRequestHeader("Content-type", urlRequest.contentType);
-                req.requestHeaders.push(hdr);
-                req.data = new flash.net.URLVariables(HTTPUtils.encodeUrlVariables(urlRequest.data));
+				var contentSet:Boolean = false;
+				for each (var requestHeader:org.apache.flex.net.URLRequestHeader in urlRequest.requestHeaders)
+				{
+					if(requestHeader.name.toLowerCase() == "content-type")
+					{
+						contentSet = true;
+						req.contentType = requestHeader.value;
+					}
+					req.requestHeaders.push(requestHeader)
+				}
+				if(!contentSet)
+				{
+					req.requestHeaders.push(new flash.net.URLRequestHeader("Content-type", urlRequest.contentType));
+					
+				}
+                req.data = urlRequest.data is BinaryData ? (urlRequest.data as BinaryData).data
: 
+					new flash.net.URLVariables(HTTPUtils.encodeUrlVariables(urlRequest.data));
                 req.method = urlRequest.method;
 				flashUrlStream.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, flash_status);
 				flashUrlStream.addEventListener(HTTPStatusEvent.HTTP_STATUS, flash_status);


Mime
View raw message