public static async Task <string> ToHttpStringAsync(this HttpResponseMessage me) { var startLine = new StatusLine(new HttpProtocol($"HTTP/{me.Version.Major}.{me.Version.Minor}"), me.StatusCode).ToString(); string headers = ""; if (me.Headers != null && me.Headers.Count() != 0) { var headerSection = HeaderSection.CreateNew(me.Headers); headers += headerSection.ToString(endWithTwoCRLF: false); } string messageBody = ""; if (me.Content != null) { if (me.Content.Headers != null && me.Content.Headers.Count() != 0) { var headerSection = HeaderSection.CreateNew(me.Content.Headers); headers += headerSection.ToString(endWithTwoCRLF: false); } messageBody = await me.Content.ReadAsStringAsync().ConfigureAwait(false); } return(startLine + headers + CRLF + messageBody); }
public static async Task <string> ToHttpStringAsync(this HttpResponseMessage me) { var startLine = new StatusLine(new HttpProtocol($"HTTP/{me.Version.Major}.{me.Version.Minor}"), me.StatusCode).ToString(); var headers = ""; if (me.Headers.NotNullAndNotEmpty()) { var headerSection = HeaderSection.CreateNew(me.Headers); headers += headerSection.ToString(endWithTwoCRLF: false); } var messageBody = ""; if (!(me.Content is null)) { if (me.Content.Headers.NotNullAndNotEmpty()) { var headerSection = HeaderSection.CreateNew(me.Content.Headers); headers += headerSection.ToString(endWithTwoCRLF: false); } messageBody = await me.Content.ReadAsStringAsync(); } return(startLine + headers + CRLF + messageBody); }
public static async Task <HeaderSection> CreateNewAsync(string headersString) { headersString = HeaderField.CorrectObsFolding(headersString); var hs = new HeaderSection(); if (headersString.EndsWith(CRLF + CRLF)) { headersString = headersString.TrimEnd(CRLF, StringComparison.Ordinal); } using var reader = new StringReader(headersString); while (true) { var field = reader.ReadLine(strictCRLF: true); if (field is null) { break; } hs.Fields.Add(await HeaderField.CreateNewAsync(field).ConfigureAwait(false)); } ValidateAndCorrectHeaders(hs); return(hs); }
protected override void HandleColumnRemoved(object sender, ColumnEventArgs e) { base.HandleColumnRemoved(sender, e); HeaderSection section = (HeaderSection)_headerMap [e.Column]; if (section != null) { _headerMap.Remove(e.Column); _headerControl.Sections.Remove(section); } if (e.Column.SizeToContent) { lock ( _sizeToContentItemWidths ) { _sizeToContentItemWidths.Remove(e.Column); } _sizeToContentColumnCount--; } if (e.Column.AutoSize) { _autoSizeColumnCount--; } if (!_columnCollection.BatchUpdating) { ProcessColumnUpdate(false); } }
public override RowSection CreateRowSection( ListControl listControl, RowIdentifier rowIdentifier, HeaderSection headerSection, int position) { return(new MyRowSection(listControl, rowIdentifier, headerSection, position, _style)); }
protected override void UnhookHeaderControl() { _headerControl.Sections.Clear(); _arrangeByHeaderSection = null; _sortOrderHeaderSection = null; _headerControl.SectionClick -= new HeaderSectionEventHandler(HandleSectionClick); _headerControl.BeforeSectionTrack -= new HeaderSectionWidthConformableEventHandler(HandleBeforeSectionTrack); _headerControl.BeforeSectionDrag -= new HeaderSectionOrderConformableEventHandler(HandleBeforeSectionDrag); }
public MyRowSection( ListControl listControl, RowIdentifier rowIdentifier, HeaderSection headerSection, int position) : base(listControl, rowIdentifier, headerSection, position) { _position = position; }
private FileValidity LoadFileSections() { m_sections.Clear(); if (m_fileData.Length < MinimumFileSize) { return(FileValidity.NotDiablo2File); } int offset = 0; m_headerSection = new HeaderSection(m_fileData); m_sections.Add(m_headerSection); offset += m_headerSection.Size; var validity = ValidateData(); if (validity == FileValidity.Valid) { m_questSection = new QuestSection(m_fileData, offset); m_sections.Add(m_questSection); offset += m_questSection.Size; m_waypointSection = new WaypointSection(m_fileData, offset); m_sections.Add(m_waypointSection); offset += m_waypointSection.Size; m_npcSection = new NpcSection(m_fileData, offset); m_sections.Add(m_npcSection); offset += m_npcSection.Size; m_statsSection = new StatsSection(m_fileData, offset); m_sections.Add(m_statsSection); offset += m_statsSection.Size; m_skillSection = new SkillSection(m_fileData, offset, m_headerSection.SkillSectionLength); m_sections.Add(m_skillSection); offset += m_skillSection.Size; m_itemSection = new ItemListSection(m_fileData, offset); m_sections.Add(m_itemSection); offset += m_itemSection.Size; m_corpseSection = new ItemListSection(m_fileData, offset); m_sections.Add(m_corpseSection); offset += m_corpseSection.Size; m_mercenarySection = new MercenaryItemSection(m_fileData, offset); m_sections.Add(m_mercenarySection); offset += m_mercenarySection.Size; //if (offset != m_fileData.Length) // validity = FileValidity.UnknownError; } return(validity); }
public MyRowSection( ListControl listControl, RowIdentifier rowIdentifier, HeaderSection headerSection, int position, Style style) : base(listControl, rowIdentifier, headerSection, position) { _style = style; }
protected override void HandleSortIconChanged(object sender, EventArgs e) { JetListViewColumn col = (JetListViewColumn)sender; HeaderSection section = (HeaderSection)_headerMap [col]; if (section != null) { SetHeaderSortIcon(section, col); } }
private JetListViewColumn ColumnFromHeaderSection(HeaderSection item) { foreach (DictionaryEntry de in _headerMap) { if (de.Value == item) { return((JetListViewColumn)de.Key); } } return(null); }
protected override void HookHeaderControl() { _headerControl.Sections.Clear(); _arrangeByHeaderSection = new HeaderSection("Arranged By: ", Math.Max(50, _visibleWidth - 100)); _headerControl.Sections.Add(_arrangeByHeaderSection); _sortOrderHeaderSection = new HeaderSection("Sort", 100); _headerControl.Sections.Add(_sortOrderHeaderSection); UpdateSortColumn(null); _headerControl.SectionClick += new HeaderSectionEventHandler(HandleSectionClick); _headerControl.BeforeSectionTrack += new HeaderSectionWidthConformableEventHandler(HandleBeforeSectionTrack); _headerControl.BeforeSectionDrag += new HeaderSectionOrderConformableEventHandler(HandleBeforeSectionDrag); }
public MainScriptSCL(string name, string dsc, string authorName, Repository repo) : base(name, authorName, repo) { InitialComments.CommentStr = string.Format("Browser:IE5 \n" + "!Date:{0}\n", CreationDate); Sections.Add(new EnviromentSection(dsc)); Header = new HeaderSection(); Sections.Add(Header); Code = new CodeSection(); Sections.Add(Code); AddVariable(new Variable(Name.Replace(".htp", ""), "Timer", VariablesScopes.Local)); Sections.Add(new StartTimer(Name.Replace(".htp", ""))); }
private void UpdateHeaderControl() { if (_headerControl == null) { return; } int accumulatedWidth = 0; int colIndex = 0; HashSet usedHeaderSections = new HashSet(); foreach (JetListViewColumn col in _columnCollection) { if (col.ShowHeader) { HeaderSection section = (HeaderSection)_headerMap [col]; if (section == null) { section = new HeaderSection(col.Text, col.Width + accumulatedWidth); _headerControl.Sections.Insert(colIndex, section); _headerMap [col] = section; } else { section.Width = col.Width + accumulatedWidth; section.Text = col.Text; if (section.Index != colIndex) { _headerControl.Sections.Remove(section); _headerControl.Sections.Insert(colIndex, section); } } SetHeaderSortIcon(section, col); usedHeaderSections.Add(section); colIndex++; accumulatedWidth = 0; } else if (!col.IsIndentColumn()) { accumulatedWidth += col.Width; } } for (int i = _headerControl.Sections.Count - 1; i >= 0; i--) { if (!usedHeaderSections.Contains(_headerControl.Sections [i])) { _headerControl.Sections.RemoveAt(i); } } }
public static void RemoveInvalidTrailers(HeaderSection trailerHeaderSection) { // https://tools.ietf.org/html/rfc7230#section-4.1.2 // A sender MUST NOT generate a trailer that contains a field necessary // for message framing (e.g., Transfer - Encoding and Content - Length), trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Transfer-Encoding"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Content-Length"); // routing (e.g., Host) // request modifiers(e.g., controls and // https://tools.ietf.org/html/rfc7231#section-5.1 trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Cache-Control"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Expect"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Host"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Max-Forwards"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Pragma"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Range"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "TE"); // conditionals in Section 5 of[RFC7231]), // https://tools.ietf.org/html/rfc7231#section-5.2 trailerHeaderSection.Fields.RemoveAll(x => x.Name == "If-Match"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "If-None-Match"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "If-Modified-Since"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "If-Unmodified-Since"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "If-Range"); // authentication(e.g., see [RFC7235] // https://tools.ietf.org/html/rfc7235#section-5.3 trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Authorization"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Proxy-Authenticate"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Proxy-Authorization"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "WWW-Authenticate"); // and[RFC6265]), // https://tools.ietf.org/html/rfc6265 trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Set-Cookie"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Cookie"); // response control data(e.g., see Section 7.1 of[RFC7231]), // https://tools.ietf.org/html/rfc7231#section-7.1 trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Age"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Cache-Control"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Expires"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Date"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Location"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Retry-After"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Vary"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Warning"); // or determining how to process the payload(e.g., // Content - Encoding, Content - Type, Content - Range, and Trailer). trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Content-Encoding"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Content-Type"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Content-Range"); trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Trailer"); }
public static async Task <string> ToHttpStringAsync(this HttpRequestMessage me, CancellationToken ctsToken = default(CancellationToken)) { // https://tools.ietf.org/html/rfc7230#section-5.4 // The "Host" header field in a request provides the host and port // information from the target URI, enabling the origin server to // distinguish among resources while servicing requests for multiple // host names on a single IP address. // Host = uri - host[":" port] ; Section 2.7.1 // A client MUST send a Host header field in all HTTP/1.1 request messages. if (me.Method != new HttpMethod("CONNECT")) { if (!me.Headers.Contains("Host")) { // https://tools.ietf.org/html/rfc7230#section-5.4 // If the target URI includes an authority component, then a // client MUST send a field-value for Host that is identical to that // authority component, excluding any userinfo subcomponent and its "@" // delimiter(Section 2.7.1).If the authority component is missing or // undefined for the target URI, then a client MUST send a Host header // field with an empty field - value. me.Headers.TryAddWithoutValidation("Host", me.RequestUri.Authority); } } var startLine = new RequestLine(me.Method, me.RequestUri, new HttpProtocol($"HTTP/{me.Version.Major}.{me.Version.Minor}")).ToString(); string headers = ""; if (me.Headers != null && me.Headers.Count() != 0) { var headerSection = HeaderSection.CreateNew(me.Headers); headers += headerSection.ToString(endWithTwoCRLF: false); } string messageBody = ""; if (me.Content != null) { if (me.Content.Headers != null && me.Content.Headers.Count() != 0) { var headerSection = HeaderSection.CreateNew(me.Content.Headers); headers += headerSection.ToString(endWithTwoCRLF: false); } ctsToken.ThrowIfCancellationRequested(); messageBody = await me.Content.ReadAsStringAsync().ConfigureAwait(false); } return(startLine + headers + CRLF + messageBody); }
/// <summary> /// draw column divider /// </summary> /// <param name="g"></param> protected void DrawColumnDividers(Header header, Graphics g, Pen pen) { Point corner = tableControl.GetCorner(); int columnPos = 0; //draw dividers for (int i = 0; i < GetNumberOfColumnDividers(header); i++) { HeaderSection headerSection = header.Sections[i]; columnPos += tableControl.Columns[i].Width;; // int x = tableControl.tranlateXCoordinate(columnPos) - _corner.X; int x = GetColumnX(header, columnPos, i); ColumnDividerRenderer.Render(g, tableControl, pen, x, header.Height + GetClientRectangle().Top, GetClientRectangle().Bottom); } }
private ReadOnlySpan <byte> ReadHeaderSection(ReadOnlySpan <byte> fileData) { m_headerSection = new HeaderSection(fileData); m_headerSection.Validate(); // Validate file size if (m_headerSection.FileSize != fileData.Length) { throw new Diablo2FileFormatException(FileValidity.WrongSize); } m_sections.Add(m_headerSection); return(fileData.Slice(HeaderSection.FixedSize)); }
public static async Task <HttpRequestMessage> CreateNewAsync(this HttpRequestMessage me, Stream requestStream, CancellationToken ctsToken = default) { // https://tools.ietf.org/html/rfc7230#section-3 // The normal procedure for parsing an HTTP message is to read the // start - line into a structure, read each header field into a hash table // by field name until the empty line, and then use the parsed data to // determine if a message body is expected.If a message body has been // indicated, then it is read as a stream until an amount of octets // equal to the message body length is read or the connection is closed. // https://tools.ietf.org/html/rfc7230#section-3 // All HTTP/ 1.1 messages consist of a start - line followed by a sequence // of octets in a format similar to the Internet Message Format // [RFC5322]: zero or more header fields(collectively referred to as // the "headers" or the "header section"), an empty line indicating the // end of the header section, and an optional message body. // HTTP - message = start - line // * (header - field CRLF ) // CRLF // [message - body] var position = 0; string startLine = await HttpMessageHelper.ReadStartLineAsync(requestStream, ctsToken).ConfigureAwait(false); position += startLine.Length; var requestLine = RequestLine.CreateNew(startLine); var request = new HttpRequestMessage(requestLine.Method, requestLine.URI); string headers = await HttpMessageHelper.ReadHeadersAsync(requestStream, ctsToken).ConfigureAwait(false); position += headers.Length + 2; var headerSection = HeaderSection.CreateNew(headers); var headerStruct = headerSection.ToHttpRequestHeaders(); HttpMessageHelper.AssertValidHeaders(headerStruct.RequestHeaders, headerStruct.ContentHeaders); request.Content = await HttpMessageHelper.GetContentAsync(requestStream, headerStruct, ctsToken).ConfigureAwait(false); HttpMessageHelper.CopyHeaders(headerStruct.RequestHeaders, request.Headers); if (request.Content != null) { HttpMessageHelper.CopyHeaders(headerStruct.ContentHeaders, request.Content.Headers); } return(request); }
public static async Task <HttpResponseMessage> CreateNewAsync(Stream responseStream, HttpMethod requestMethod) { // https://tools.ietf.org/html/rfc7230#section-3 // The normal procedure for parsing an HTTP message is to read the // start - line into a structure, read each header field into a hash table // by field name until the empty line, and then use the parsed data to // determine if a message body is expected.If a message body has been // indicated, then it is read as a stream until an amount of octets // equal to the message body length is read or the connection is closed. // https://tools.ietf.org/html/rfc7230#section-3 // All HTTP/ 1.1 messages consist of a start - line followed by a sequence // of octets in a format similar to the Internet Message Format // [RFC5322]: zero or more header fields(collectively referred to as // the "headers" or the "header section"), an empty line indicating the // end of the header section, and an optional message body. // HTTP - message = start - line // * (header - field CRLF ) // CRLF // [message - body] string startLine = await HttpMessageHelper.ReadStartLineAsync(responseStream).ConfigureAwait(false); var statusLine = StatusLine.Parse(startLine); var response = new HttpResponseMessage(statusLine.StatusCode); string headers = await HttpMessageHelper.ReadHeadersAsync(responseStream).ConfigureAwait(false); var headerSection = await HeaderSection.CreateNewAsync(headers); var headerStruct = headerSection.ToHttpResponseHeaders(); HttpMessageHelper.AssertValidHeaders(headerStruct.ResponseHeaders, headerStruct.ContentHeaders); byte[] contentBytes = await HttpMessageHelper.GetContentBytesAsync(responseStream, headerStruct, requestMethod, statusLine).ConfigureAwait(false); contentBytes = HttpMessageHelper.HandleGzipCompression(headerStruct.ContentHeaders, contentBytes); response.Content = contentBytes is null ? null : new ByteArrayContent(contentBytes); HttpMessageHelper.CopyHeaders(headerStruct.ResponseHeaders, response.Headers); if (response.Content != null) { HttpMessageHelper.CopyHeaders(headerStruct.ContentHeaders, response.Content.Headers); } return(response); }
void LoadSections(TaggedDataReader reader) { IDXFTaggedData data; while ((data = reader.GetNext()) != null) { if (data.Code == 0 && data.Data == "SECTION") { var section = reader.GetNext(); if (section.Code == 2) { switch (section.Data) { case "HEADER": Header = new HeaderSection(reader); //Header = new DXFHeader(_reader); break; case "CLASSES": Console.WriteLine(section.Data); break; case "TABLES": Console.WriteLine(section.Data); break; case "BLOCKS": Console.WriteLine(section.Data); break; case "ENTITIES": Console.WriteLine(section.Data); break; case "OBJECTS": Console.WriteLine(section.Data); break; } } } } }
public bool WriteDbToP21File(string filename) { try { //BbInstanceList.FillP21InstanceDB(); //HeaderSection.SetHeader("mvdname", "filename", "test", "schemaversion"); HeaderSection.SetHeader(EbConstants.Em11MvdName, Path.GetFileName(filename), EbConstants.DefaultOrganization, SchemaModel.RegisteredSchema.IFC2X3.ToString()); return(EarlyBindingInstanceModel.Write(filename)); } catch (Exception ex) { var fileInfo = new StackFrame(true); //Logger.Debug(string.Format("File : {0}\nLine : {1}\nException : {2}\nTrace : {3}", // fileInfo.GetFileName(), fileInfo.GetFileLineNumber(), ex.Message, // ex.StackTrace)); return(false); } }
private void Read(BinaryReader reader) { // determine where all the sections are HeaderSection = new(reader); ProtocolSection = new(reader); AdcSection = new(reader); DacSection = new(reader); StringsSection = new(reader); TagSection = new(reader); DataSection = new(reader); SynchArraySection = new(reader); EpochSection = new(reader); EpochPerDacSection = new(reader); AdcPerDacSection = new(reader); UserListSection = new(reader); StatsRegionSection = new(reader); MathSection = new(reader); ScopeSection = new(reader); DeltaSection = new(reader); VoiceTagSection = new(reader); AnnotationSection = new(reader); StatsSection = new(reader); // populate header values from each section ReadGroup1(); ReadGroup2(); ReadGroup3(); ReadGroup5(); ReadGroup6(); ReadGroup7(); ReadGroup9(); ReadGroup10(); ReadGroup12(); // use header values to put additional information in the header object float tagTimeMult = (fSynchTimeUnit == 0) ? SamplePeriod / ChannelCount : fSynchTimeUnit / 1e6f; Tags = TagSection.GetTags(tagTimeMult); }
private IEnumerable <FileSection> BreakIntoSections(Tuple <string, string[]> fileInfo) { using (var fileSystem = _fileSystemFactory.CreateExport()) { string message = $"Splitting paragraphs: {fileSystem.Value.Path.GetFileName(fileInfo.Item1)}"; const string commandStart = "---- CMD:"; Debug.WriteLine(message); _logger.Log(message, Category.Info, Priority.None); var headerSection = new HeaderSection( fileInfo.Item1, 0, fileInfo.Item2.TakeWhile(line => !line.StartsWith(commandStart))); var paragraphs = fileInfo.Item2 .Skip(headerSection.Lines.Count()) .Aggregate( new List <List <string> >(), (list, value) => { if (value.StartsWith(commandStart)) { list.Add(new List <string>()); } list.Last().Add(value); return(list); }); var result = paragraphs.Select((paragraph, index) => new CommandSection(fileInfo.Item1, index + 1, paragraph.First().Substring(commandStart.Length).Trim(), paragraph)).ToList(); string completeMessage = $"Completed {char.ToLowerInvariant(message[0]) + message.Substring(1)}"; Debug.WriteLine(completeMessage); _logger.Log(completeMessage, Category.Info, Priority.None); return(new FileSection[] { headerSection }.Concat(result)); } }
protected override void CreateViews() { if (m_background == null) { m_background = new BackgroundSection(); m_background.Initialize(); } if (m_header == null) { m_header = new HeaderSection(); m_header.Initialize(); } if (m_characterList == null) { m_characterList = new CharacterListSection(); m_characterList.Initialize(); } if (m_createHolder == null) { m_createHolder = new CreateHolderSection(); m_createHolder.Initialize(); } if (m_characterCreation == null) { m_characterCreation = new CharacterCreationSection(); m_characterCreation.Initialize(); } if (m_defaultSection == null) { m_defaultSection = new DefaultSection(); m_defaultSection.Initialize(); } }
public async Task <HeaderSection> HeaderDetailsMapping(string transcationType) { HeaderSection HeaderSectionObject = new HeaderSection(); try { HeaderSectionObject.TransactionID = GenerateTranscationNo().ToString(); HeaderSectionObject.SenderID = ShipaConfiguration.SenderID(); HeaderSectionObject.ReceiverID = ShipaConfiguration.ReceiverID(); HeaderSectionObject.UserID = ShipaConfiguration.ShipaClientID(); HeaderSectionObject.CreatedDateTime = System.DateTime.Now; HeaderSectionObject.CreatedDateTimeZone = ShipaConfiguration.CreatedDateTimeZone(); HeaderSectionObject.VersionNumber = ShipaConfiguration.VersionNumber(); HeaderSectionObject.TransactionType = transcationType; HeaderSectionObject.PartnerID = ShipaConfiguration.PartnerID(); HeaderSectionObject.Criteria = 0; } catch (Exception ex) { throw ex; } return(await Task.Run(() => HeaderSectionObject).ConfigureAwait(false)); }
private static void ValidateAndCorrectHeaders(HeaderSection hs) { // https://tools.ietf.org/html/rfc7230#section-5.4 // Since the Host field - value is critical information for handling a // request, a user agent SHOULD generate Host as the first header field // following the request - line. HeaderField?hostToCorrect = null; foreach (var f in hs.Fields) { // if we find host if (f.IsNameEqual("Host")) { // if host is not first if (!hs.Fields.First().IsNameEqual("Host")) { // then correct host hostToCorrect = f; break; } } } if (hostToCorrect is { })
private PhotoshopFile( [NotNull] Stream stream, [NotNull] PhotoshopFileSectionReader <HeaderSection> headerSectionReader, [NotNull] PhotoshopFileSectionReader <ColorModeDataSection> colorModeDataSectionReader, [NotNull] PhotoshopFileSectionReader <ImageResourcesSection> imageResourcesSectionReader, [NotNull] PhotoshopFileSectionReader <LayerMaskInformationSection> layerMaskInformationSectionReader, [NotNull] PhotoshopFileSectionReader <ImageDataSection> imageDataSectionReader) { Assert.NotNull(stream, nameof(stream)); Assert.NotNull(headerSectionReader, nameof(headerSectionReader)); Assert.NotNull(colorModeDataSectionReader, nameof(colorModeDataSectionReader)); Assert.NotNull(imageResourcesSectionReader, nameof(imageResourcesSectionReader)); Assert.NotNull(layerMaskInformationSectionReader, nameof(layerMaskInformationSectionReader)); Assert.NotNull(imageDataSectionReader, nameof(imageDataSectionReader)); _stream = stream; _reader = new PhotoshopFileReader(stream); _headerSection = headerSectionReader.ReadSection(_reader, this); _colorModeDataSection = colorModeDataSectionReader.ReadSection(_reader, this); _imageResourcesSection = imageResourcesSectionReader.ReadSection(_reader, this); _layerMaskInformationSection = layerMaskInformationSectionReader.ReadSection(_reader, this); _imageDataSection = imageDataSectionReader.ReadSection(_reader, this); }
private static async Task <HttpContent> GetDecodedChunkedContentAsync(Stream stream, HttpRequestContentHeaders requestHeaders, HttpResponseContentHeaders responseHeaders, CancellationToken ctsToken = default) { if (responseHeaders == null && requestHeaders == null) { throw new ArgumentException("Response and request headers cannot be both null."); } if (responseHeaders != null && requestHeaders != null) { throw new ArgumentException("Either response or request headers has to be null."); } // https://tools.ietf.org/html/rfc7230#section-4.1.3 // 4.1.3.Decoding Chunked // A process for decoding the chunked transfer coding can be represented // in pseudo - code as: // length := 0 // read chunk - size, chunk - ext(if any), and CRLF // while (chunk - size > 0) // { // read chunk-data and CRLF // append chunk-data to decoded-body // length:= length + chunk - size // read chunk-size, chunk - ext(if any), and CRLF // } // read trailer field // while (trailer field is not empty) { // if (trailer field is allowed to be sent in a trailer) { // append trailer field to existing header fields // } // read trailer-field // } // Content - Length := length // Remove "chunked" from Transfer-Encoding // Remove Trailer from existing header fields long length = 0; var firstChunkLine = await ReadCRLFLineAsync(stream, Encoding.ASCII, ctsToken : ctsToken); ParseFistChunkLine(firstChunkLine, out long chunkSize, out IEnumerable <string> chunkExtensions); // We will not do anything with the chunk extensions, because: // https://tools.ietf.org/html/rfc7230#section-4.1.1 // A recipient MUST ignore unrecognized chunk extensions. var decodedBody = new List <byte>(); // https://tools.ietf.org/html/rfc7230#section-4.1 // The chunked transfer coding is complete // when a chunk with a chunk-size of zero is received, possibly followed // by a trailer, and finally terminated by an empty line. while (chunkSize > 0) { var chunkData = await ReadBytesTillLengthAsync(stream, chunkSize, ctsToken); if (await ReadCRLFLineAsync(stream, Encoding.ASCII, ctsToken) != "") { throw new FormatException("Chunk does not end with CRLF."); } foreach (var b in chunkData) { decodedBody.Add(b); } length += chunkSize; firstChunkLine = await ReadCRLFLineAsync(stream, Encoding.ASCII, ctsToken : ctsToken); ParseFistChunkLine(firstChunkLine, out long cs, out IEnumerable <string> ces); chunkSize = cs; chunkExtensions = ces; } // https://tools.ietf.org/html/rfc7230#section-4.1.2 // A trailer allows the sender to include additional fields at the end // of a chunked message in order to supply metadata that might be // dynamically generated while the message body is sent string trailerHeaders = await ReadHeadersAsync(stream, ctsToken); var trailerHeaderSection = HeaderSection.CreateNew(trailerHeaders); RemoveInvalidTrailers(trailerHeaderSection); if (responseHeaders != null) { var trailerHeaderStruct = trailerHeaderSection.ToHttpResponseHeaders(); AssertValidHeaders(trailerHeaderStruct.ResponseHeaders, trailerHeaderStruct.ContentHeaders); // https://tools.ietf.org/html/rfc7230#section-4.1.2 // When a chunked message containing a non-empty trailer is received, // the recipient MAY process the fields(aside from those forbidden // above) as if they were appended to the message's header section. CopyHeaders(trailerHeaderStruct.ResponseHeaders, responseHeaders.ResponseHeaders); responseHeaders.ResponseHeaders.Remove("Transfer-Encoding"); responseHeaders.ContentHeaders.TryAddWithoutValidation("Content-Length", length.ToString()); responseHeaders.ResponseHeaders.Remove("Trailer"); } if (requestHeaders != null) { var trailerHeaderStruct = trailerHeaderSection.ToHttpRequestHeaders(); AssertValidHeaders(trailerHeaderStruct.RequestHeaders, trailerHeaderStruct.ContentHeaders); // https://tools.ietf.org/html/rfc7230#section-4.1.2 // When a chunked message containing a non-empty trailer is received, // the recipient MAY process the fields(aside from those forbidden // above) as if they were appended to the message's header section. CopyHeaders(trailerHeaderStruct.RequestHeaders, requestHeaders.RequestHeaders); requestHeaders.RequestHeaders.Remove("Transfer-Encoding"); requestHeaders.ContentHeaders.TryAddWithoutValidation("Content-Length", length.ToString()); requestHeaders.RequestHeaders.Remove("Trailer"); } return(new ByteArrayContent(decodedBody.ToArray())); }
public HomePage(IWebDriver driver, IWait <IWebDriver> wait) : base(driver, wait) { this.header = new HeaderSection(driver, wait); this.footer = new FooterSection(driver, wait); }