コード例 #1
0
 protected void Uninit()
 {
     this._data   = null;
     this._offset = 0;
     this._length = 0;
     this._pos    = 0;
 }
        internal static MultipartContentElement[] Parse(HttpRawUploadedContent data, int length, byte[] boundary, Encoding encoding)
        {
            HttpMultipartContentTemplateParser parser = new HttpMultipartContentTemplateParser(data, length, boundary, encoding);

            parser.ParseIntoElementList();
            return((MultipartContentElement[])parser._elements.ToArray(typeof(MultipartContentElement)));
        }
コード例 #3
0
 protected void Uninit()
 {
     _data   = null;
     _offset = 0;
     _length = 0;
     _pos    = 0;
 }
コード例 #4
0
 protected void Init(HttpRawUploadedContent data, int offset, int length)
 {
     this._data   = data;
     this._offset = offset;
     this._length = length;
     this._pos    = 0;
 }
 private HttpMultipartContentTemplateParser(HttpRawUploadedContent data, int length, byte[] boundary, Encoding encoding)
 {
     this._data = data;
     this._length = length;
     this._boundary = boundary;
     this._encoding = encoding;
 }
コード例 #6
0
 protected void Init(HttpRawUploadedContent data, int offset, int length)
 {
     _data   = data;
     _offset = offset;
     _length = length;
     _pos    = 0;
 }
 protected void Init(HttpRawUploadedContent data, int offset, int length)
 {
     this._data = data;
     this._offset = offset;
     this._length = length;
     this._pos = 0;
 }
 private HttpMultipartContentTemplateParser(HttpRawUploadedContent data, int length, byte[] boundary, Encoding encoding)
 {
     this._data     = data;
     this._length   = length;
     this._boundary = boundary;
     this._encoding = encoding;
 }
コード例 #9
0
 internal MultipartContentElement(String name, String filename, String contentType, HttpRawUploadedContent data, int offset, int length) {
     _name = name;
     _filename = filename;
     _contentType = contentType;
     _data = data;
     _offset = offset;
     _length = length;
 }
コード例 #10
0
 internal MultipartContentElement(String name, String filename, String contentType, HttpRawUploadedContent data, int offset, int length)
 {
     _name        = name;
     _filename    = filename;
     _contentType = contentType;
     _data        = data;
     _offset      = offset;
     _length      = length;
 }
 internal MultipartContentElement(string name, string filename, string contentType, HttpRawUploadedContent data, int offset, int length)
 {
     this._name = name;
     this._filename = filename;
     this._contentType = contentType;
     this._data = data;
     this._offset = offset;
     this._length = length;
 }
コード例 #12
0
 private void SetRawContentOnce()
 {
     if (_persistEntityBody && _rawContent != null)
     {
         _rawContent.DoneAddingBytes();
         _context.Request.SetRawContent(_rawContent);
         _rawContent = null;
     }
 }
コード例 #13
0
 internal MultipartContentElement(string name, string filename, string contentType, HttpRawUploadedContent data, int offset, int length)
 {
     this._name        = name;
     this._filename    = filename;
     this._contentType = contentType;
     this._data        = data;
     this._offset      = offset;
     this._length      = length;
 }
 internal void SetContent(HttpRawUploadedContent data)
 {
     if (data != null)
     {
         base.Init(data, 0, data.Length);
     }
     else
     {
         base.Uninit();
     }
 }
コード例 #15
0
        internal HttpBufferlessInputStream(HttpContext context, bool persistEntityBody, bool disableMaxRequestLength) {
            _context = context;
            _persistEntityBody = persistEntityBody;
            _disableMaxRequestLength = disableMaxRequestLength;

            // Check max-request-length for preloaded content
            HttpRuntimeSection section = RuntimeConfig.GetConfig(_context).HttpRuntime;
            _maxRequestLength = section.MaxRequestLengthBytes;
            _fileThreshold = section.RequestLengthDiskThresholdBytes;

            if (_persistEntityBody) {
                _rawContent = new HttpRawUploadedContent(_fileThreshold, _context.Request.ContentLength);
            }
            
            int contentLength = _context.Request.ContentLength;
            _remainingBytes = (contentLength > 0) ? contentLength : Int32.MaxValue;
            _length = contentLength;
        }
コード例 #16
0
        internal HttpBufferlessInputStream(HttpContext context, bool persistEntityBody, bool disableMaxRequestLength)
        {
            _context                 = context;
            _persistEntityBody       = persistEntityBody;
            _disableMaxRequestLength = disableMaxRequestLength;

            // Check max-request-length for preloaded content
            HttpRuntimeSection section = RuntimeConfig.GetConfig(_context).HttpRuntime;

            _maxRequestLength = section.MaxRequestLengthBytes;
            _fileThreshold    = section.RequestLengthDiskThresholdBytes;

            if (_persistEntityBody)
            {
                _rawContent = new HttpRawUploadedContent(_fileThreshold, _context.Request.ContentLength);
            }

            int contentLength = _context.Request.ContentLength;

            _remainingBytes = (contentLength > 0) ? contentLength : Int32.MaxValue;
            _length         = contentLength;
        }
コード例 #17
0
ファイル: HttpRequest.cs プロジェクト: Alister742/ParseKit
        /*
         * Read entire raw content as byte array 
         */
        private HttpRawUploadedContent GetEntireRawContent()
        {
            if (_wr == null)
                return null;

            if (_rawContent != null)
                return _rawContent;

            // enforce the limit 
            HttpRuntimeSection cfg = RuntimeConfig.GetConfig(_context).HttpRuntime;
            int limit = cfg.MaxRequestLengthBytes;
            if (ContentLength > limit)
            {
                if (!(_wr is IIS7WorkerRequest))
                {
                    Response.CloseConnectionAfterError();
                }
                throw new HttpException(SR.GetString(SR.Max_request_length_exceeded),
                                        null, WebEventCodes.RuntimeErrorPostTooLarge);
            }

            // threshold to go to file

            int fileThreshold = cfg.RequestLengthDiskThresholdBytes;

            // read the preloaded content 

            HttpRawUploadedContent rawContent = new HttpRawUploadedContent(fileThreshold, ContentLength);

            byte[] preloadedContent = _wr.GetPreloadedEntityBody();

            if (preloadedContent != null)
            {
                _wr.UpdateRequestCounters(preloadedContent.Length);
                rawContent.AddBytes(preloadedContent, 0, preloadedContent.Length);
            }

            // read the remaing content

            if (!_wr.IsEntireEntityBodyIsPreloaded())
            {
                int remainingBytes = (ContentLength > 0) ? ContentLength - rawContent.Length : Int32.MaxValue;

                HttpApplication app = _context.ApplicationInstance;
                byte[] buf = (app != null) ? app.EntityBuffer : new byte[8 * 1024];
                int numBytesRead = rawContent.Length;

                while (remainingBytes > 0)
                {
                    int bytesToRead = buf.Length;
                    if (bytesToRead > remainingBytes)
                        bytesToRead = remainingBytes;

                    int bytesRead = _wr.ReadEntityBody(buf, bytesToRead);
                    if (bytesRead <= 0)
                        break;

                    _wr.UpdateRequestCounters(bytesRead);

                    _readEntityBody = true;
                    rawContent.AddBytes(buf, 0, bytesRead);

                    remainingBytes -= bytesRead;
                    numBytesRead += bytesRead;

                    if (numBytesRead > limit)
                    {
                        throw new HttpException(SR.GetString(SR.Max_request_length_exceeded),
                                    null, WebEventCodes.RuntimeErrorPostTooLarge);
                    }
                }
            }

            rawContent.DoneAddingBytes();

            // filter content 

            if (_installedFilter != null)
            {
                if (rawContent.Length > 0)
                {
                    try
                    {
                        try
                        {
                            _filterSource.SetContent(rawContent);

                            HttpRawUploadedContent filteredRawContent = new HttpRawUploadedContent(fileThreshold, rawContent.Length);
                            HttpApplication app = _context.ApplicationInstance;
                            byte[] buf = (app != null) ? app.EntityBuffer : new byte[8 * 1024];

                            for (; ; )
                            {
                                int bytesRead = _installedFilter.Read(buf, 0, buf.Length);
                                if (bytesRead == 0)
                                    break;
                                filteredRawContent.AddBytes(buf, 0, bytesRead);
                            }

                            filteredRawContent.DoneAddingBytes();
                            rawContent = filteredRawContent;
                        }
                        finally
                        {
                            _filterSource.SetContent(null);
                        }
                    }
                    catch
                    { // Protect against exception filters 
                        throw;
                    }
                }
            }

            _rawContent = rawContent;
            return _rawContent;
        }
コード例 #18
0
 internal HttpInputStream(HttpRawUploadedContent data, int offset, int length)
 {
     this.Init(data, offset, length);
 }
コード例 #19
0
 protected void Uninit()
 {
     this._data = null;
     this._offset = 0;
     this._length = 0;
     this._pos = 0;
 }
コード例 #20
0
 private void SetRawContentOnce() {
     if (_persistEntityBody && _rawContent != null) {
         _rawContent.DoneAddingBytes();
         _context.Request.SetRawContent(_rawContent);
         _rawContent = null;
     }
 }
コード例 #21
0
ファイル: HttpRequest.cs プロジェクト: uQr/referencesource
 internal void SetRawContent(HttpRawUploadedContent rawContent) {
     Debug.Assert(rawContent != null);
     if (rawContent.Length > 0) {
         NeedToInsertEntityBody = true;
     }
     _rawContent = rawContent;
 }
コード例 #22
0
 /*
  * Static method to do the parsing
  */
 internal static MultipartContentElement[] Parse(HttpRawUploadedContent data, int length, byte[] boundary, Encoding encoding) {
     HttpMultipartContentTemplateParser parser = new HttpMultipartContentTemplateParser(data, length, boundary, encoding);
     parser.ParseIntoElementList();
     return (MultipartContentElement[])parser._elements.ToArray(typeof(MultipartContentElement));
 }
コード例 #23
0
 private HttpRawUploadedContent GetEntireRawContent()
 {
     if (this._wr == null)
     {
         return null;
     }
     if (this._rawContent == null)
     {
         HttpRuntimeSection httpRuntime = RuntimeConfig.GetConfig(this._context).HttpRuntime;
         int maxRequestLengthBytes = httpRuntime.MaxRequestLengthBytes;
         if (this.ContentLength > maxRequestLengthBytes)
         {
             if (!(this._wr is IIS7WorkerRequest))
             {
                 this.Response.CloseConnectionAfterError();
             }
             throw new HttpException(System.Web.SR.GetString("Max_request_length_exceeded"), null, 0xbbc);
         }
         int requestLengthDiskThresholdBytes = httpRuntime.RequestLengthDiskThresholdBytes;
         HttpRawUploadedContent data = new HttpRawUploadedContent(requestLengthDiskThresholdBytes, this.ContentLength);
         byte[] preloadedEntityBody = this._wr.GetPreloadedEntityBody();
         if (preloadedEntityBody != null)
         {
             this._wr.UpdateRequestCounters(preloadedEntityBody.Length);
             data.AddBytes(preloadedEntityBody, 0, preloadedEntityBody.Length);
         }
         if (!this._wr.IsEntireEntityBodyIsPreloaded())
         {
             int num3 = (this.ContentLength > 0) ? (this.ContentLength - data.Length) : 0x7fffffff;
             HttpApplication applicationInstance = this._context.ApplicationInstance;
             byte[] buffer = (applicationInstance != null) ? applicationInstance.EntityBuffer : new byte[0x2000];
             int length = data.Length;
             while (num3 > 0)
             {
                 int size = buffer.Length;
                 if (size > num3)
                 {
                     size = num3;
                 }
                 int bytesIn = this._wr.ReadEntityBody(buffer, size);
                 if (bytesIn <= 0)
                 {
                     break;
                 }
                 this._wr.UpdateRequestCounters(bytesIn);
                 this.NeedToInsertEntityBody = true;
                 data.AddBytes(buffer, 0, bytesIn);
                 num3 -= bytesIn;
                 length += bytesIn;
                 if (length > maxRequestLengthBytes)
                 {
                     throw new HttpException(System.Web.SR.GetString("Max_request_length_exceeded"), null, 0xbbc);
                 }
             }
         }
         data.DoneAddingBytes();
         if ((this._installedFilter != null) && (data.Length > 0))
         {
             try
             {
                 try
                 {
                     this._filterSource.SetContent(data);
                     HttpRawUploadedContent content2 = new HttpRawUploadedContent(requestLengthDiskThresholdBytes, data.Length);
                     HttpApplication application2 = this._context.ApplicationInstance;
                     byte[] buffer3 = (application2 != null) ? application2.EntityBuffer : new byte[0x2000];
                     while (true)
                     {
                         int num7 = this._installedFilter.Read(buffer3, 0, buffer3.Length);
                         if (num7 == 0)
                         {
                             break;
                         }
                         content2.AddBytes(buffer3, 0, num7);
                     }
                     content2.DoneAddingBytes();
                     data = content2;
                 }
                 finally
                 {
                     this._filterSource.SetContent(null);
                 }
             }
             catch
             {
                 throw;
             }
         }
         this._rawContent = data;
     }
     return this._rawContent;
 }
コード例 #24
0
 internal HttpInputStream(HttpRawUploadedContent data, int offset, int length)
 {
     this.Init(data, offset, length);
 }
コード例 #25
0
 protected void Init(HttpRawUploadedContent data, int offset, int length) {
     _data = data;
     _offset = offset;
     _length = length;
     _pos = 0; 
 }
コード例 #26
0
ファイル: HttpRequest.cs プロジェクト: uQr/referencesource
 private void ApplyFilter(ref HttpRawUploadedContent rawContent, int fileThreshold) {
     if (_installedFilter != null) {
         _filterApplied = true;
         if (rawContent.Length > 0) {
             try {
                 try {
                     _filterSource.SetContent(rawContent);
                     
                     HttpRawUploadedContent filteredRawContent = new HttpRawUploadedContent(fileThreshold, rawContent.Length);
                     HttpApplication app = _context.ApplicationInstance;
                     byte[] buf = (app != null) ? app.EntityBuffer : new byte[8 * 1024];
                     
                     for (;;) {
                         int bytesRead = _installedFilter.Read(buf, 0, buf.Length);
                         if (bytesRead == 0)
                             break;
                         filteredRawContent.AddBytes(buf, 0, bytesRead);
                     }
                     
                     filteredRawContent.DoneAddingBytes();
                     rawContent = filteredRawContent;
                 }
                 finally {
                     _filterSource.SetContent(null);
                 }
             }
             catch { // Protect against exception filters
                 throw;
             }
         }
     }
 }
コード例 #27
0
 protected void Uninit() {
     _data = null;
     _offset = 0;
     _length = 0;
     _pos = 0;
 }
コード例 #28
0
ファイル: HttpRequest.cs プロジェクト: uQr/referencesource
        /*
         * Read entire raw content as byte array
         */
        private HttpRawUploadedContent GetEntireRawContent() {
            if (_wr == null)
                return null;

            if (_rawContent != null) {
                // if _rawContent was set by HttpBufferlessInputStream, then we will apply the filter here
                if (_installedFilter != null && !_filterApplied) {
                    ApplyFilter(ref _rawContent, RuntimeConfig.GetConfig(_context).HttpRuntime.RequestLengthDiskThresholdBytes);
                }
                return _rawContent;
            }

            if (_readEntityBodyMode == ReadEntityBodyMode.None) {
                _readEntityBodyMode = ReadEntityBodyMode.Classic;
            }
            else if (_readEntityBodyMode == ReadEntityBodyMode.Buffered) {
                // _rawContent should have been set already
                throw new InvalidOperationException(SR.GetString(SR.Invalid_operation_with_get_buffered_input_stream));
            }
            else if (_readEntityBodyMode == ReadEntityBodyMode.Bufferless) {
                throw new HttpException(SR.GetString(SR.Incompatible_with_get_bufferless_input_stream));
            }

            // enforce the limit
            HttpRuntimeSection cfg = RuntimeConfig.GetConfig(_context).HttpRuntime;
            int limit = cfg.MaxRequestLengthBytes;
            if (ContentLength > limit) {
                if ( !(_wr is IIS7WorkerRequest) ) {
                    Response.CloseConnectionAfterError();
                }
                throw new HttpException(SR.GetString(SR.Max_request_length_exceeded),
                                        null, WebEventCodes.RuntimeErrorPostTooLarge);
            }

            // threshold to go to file

            int fileThreshold = cfg.RequestLengthDiskThresholdBytes;

            // read the preloaded content

            HttpRawUploadedContent rawContent = new HttpRawUploadedContent(fileThreshold, ContentLength);

            byte[] preloadedContent = _wr.GetPreloadedEntityBody();

            if (preloadedContent != null) {
                _wr.UpdateRequestCounters(preloadedContent.Length);
                rawContent.AddBytes(preloadedContent, 0, preloadedContent.Length);
            }

            // read the remaing content

            if (!_wr.IsEntireEntityBodyIsPreloaded()) {
                int remainingBytes = (ContentLength > 0) ? ContentLength - rawContent.Length : Int32.MaxValue;

                HttpApplication app = _context.ApplicationInstance;
                byte[] buf = (app != null) ? app.EntityBuffer : new byte[8 * 1024];
                int numBytesRead = rawContent.Length;

                while (remainingBytes > 0) {
                    int bytesToRead = buf.Length;
                    if (bytesToRead > remainingBytes)
                        bytesToRead = remainingBytes;

                    int bytesRead = _wr.ReadEntityBody(buf, bytesToRead);
                    if (bytesRead <= 0)
                        break;

                    _wr.UpdateRequestCounters(bytesRead);

                    rawContent.AddBytes(buf, 0, bytesRead);

                    remainingBytes -= bytesRead;
                    numBytesRead += bytesRead;

                    if (numBytesRead > limit) {
                        throw new HttpException(SR.GetString(SR.Max_request_length_exceeded),
                                    null, WebEventCodes.RuntimeErrorPostTooLarge);
                    }

                    // Fail synchrously if receiving the request content takes too long
                    // RequestTimeoutManager is not efficient in case of ThreadPool starvation
                    // as the timer callback doing Thread.Abort may not trigger for a long time
                    if (remainingBytes > 0 && _context.HasTimeoutExpired) {
                        throw new HttpException(SR.GetString(SR.Request_timed_out));
                    }
                }
            }

            rawContent.DoneAddingBytes();

            // filter content
            if (_installedFilter != null) {
                ApplyFilter(ref rawContent, fileThreshold);
            }

            SetRawContent(rawContent);
            return _rawContent;
        }
コード例 #29
0
 internal void SetContent(HttpRawUploadedContent data) {
     if (data != null)
         base.Init(data, 0, data.Length);
     else
         base.Uninit();
 }