Ejemplo n.º 1
0
        /// <inheritdoc />
        protected internal override void EncodeInitialLine(IByteBuffer buf, IHttpRequest request)
        {
            ByteBufferUtil.Copy(request.Method.AsciiName, buf);

            string uri = request.Uri;

            if (string.IsNullOrEmpty(uri))
            {
                // Add / as absolute path if no is present.
                // See http://tools.ietf.org/html/rfc2616#section-5.1.2
                _ = buf.WriteMedium(SpaceSlashAndSpaceMedium);
            }
            else
            {
                var uriCharSequence = new StringBuilderCharSequence();
                uriCharSequence.Append(uri);

                bool needSlash = false;
                int  start     = uri.IndexOf("://", StringComparison.Ordinal);
                if (start != -1 && uri[0] != Slash)
                {
                    start += 3;
                    // Correctly handle query params.
                    // See https://github.com/netty/netty/issues/2732
                    int index = uri.IndexOf(QuestionMark, start);
                    if (index == -1)
                    {
                        if (uri.LastIndexOf(Slash) < start)
                        {
                            needSlash = true;
                        }
                    }
                    else
                    {
                        if (uri.LastIndexOf(Slash, index) < start)
                        {
                            uriCharSequence.Insert(index, Slash);
                        }
                    }
                }

                _ = buf.WriteByte(HorizontalSpace).WriteCharSequence(uriCharSequence, Encoding.UTF8);
                if (needSlash)
                {
                    // write "/ " after uri
                    _ = buf.WriteShort(SlashAndSpaceShort);
                }
                else
                {
                    _ = buf.WriteByte(HorizontalSpace);
                }
            }

            request.ProtocolVersion.Encode(buf);
            _ = buf.WriteShort(CrlfShort);
        }
Ejemplo n.º 2
0
 static void WriteAscii(IByteBuffer buf, int offset, ICharSequence value)
 {
     if (value is AsciiString asciiString)
     {
         ByteBufferUtil.Copy(asciiString, 0, buf, offset, value.Count);
     }
     else
     {
         buf.SetCharSequence(offset, value, Encoding.ASCII);
     }
 }
Ejemplo n.º 3
0
        public static void SetFloat(byte[] dst, ref int startIndex, float value)
        {
            byte[] src = BitConverter.GetBytes(value);

            if (ByteBufferUtil.IsReveresed(_endian))
            {
                Array.Reverse(src);
            }
            ByteBufferUtil.Copy(src, 0, dst, startIndex, src.Length);

            startIndex += sizeof(float);
        }
Ejemplo n.º 4
0
 protected override void SetShort(short data)
 {
     ByteBufferUtil.Copy(BitConverter.GetBytes(data), 0, _data, _writeIndex, sizeof(short));
 }
Ejemplo n.º 5
0
 protected override void SetLong(long data)
 {
     ByteBufferUtil.Copy(BitConverter.GetBytes(data), 0, _data, _writeIndex, sizeof(long));
 }
        protected override void SetShort(short data)
        {
            var bytes = BitConverter.GetBytes(data.Reverse());

            ByteBufferUtil.Copy(bytes, 0, _data, _writeIndex, sizeof(short));
        }