Exemple #1
0
        internal static HttpVersion ValueOf(AsciiString text)
        {
            if (text is null)
            {
                ThrowHelper.ThrowArgumentException_NullText();
            }

            // ReSharper disable once PossibleNullReferenceException
            HttpVersion version = ValueOfInline(text.Array);

            if (version is object)
            {
                return(version);
            }

            // Fall back to slow path
            text = text.Trim();

            if (0u >= (uint)text.Count)
            {
                ThrowHelper.ThrowArgumentException_EmptyText();
            }

            // Try to match without convert to uppercase first as this is what 99% of all clients
            // will send anyway. Also there is a change to the RFC to make it clear that it is
            // expected to be case-sensitive
            //
            // See:
            // * http://trac.tools.ietf.org/wg/httpbis/trac/ticket/1
            // * http://trac.tools.ietf.org/wg/httpbis/trac/wiki
            //
            return(Version0(text) ?? new HttpVersion(text.ToString(), true));
        }
        public void ComparisonWithString()
        {
            const string Value = "shouldn't fail";
            var          ascii = new AsciiString(Value.ToCharArray());

            Assert.Equal(Value, ascii.ToString());
        }
Exemple #3
0
        public void GoToUrl(string url)
        {
            int         index = -1;
            nsISHistory history;

            navigation.navigation.getSessionHistory(out history);
            int             count = Count;
            nsIHistoryEntry entry;

            for (int i = 0; i < count; i++)
            {
                nsIURI uri;
                history.getEntryAtIndex(i, false, out entry);
                entry.getURI(out uri);
                AsciiString spec = new AsciiString(String.Empty);
                uri.getSpec(spec.Handle);
                if (string.Compare(spec.ToString(), url, true) == 0)
                {
                    index = i;
                    break;
                }
            }
            if (index > -1)
            {
                this.GoToIndex(index);
            }
        }
Exemple #4
0
        public void PreflightRequestAllowCredentials()
        {
            var           origin   = new AsciiString("null");
            CorsConfig    config   = CorsConfigBuilder.ForOrigin(origin).AllowCredentials().Build();
            IHttpResponse response = PreflightRequest(config, origin.ToString(), "content-type, xheader1");

            Assert.Equal("true", response.Headers.Get(HttpHeaderNames.AccessControlAllowCredentials, null));
        }
        public void WriteUsAsciiString()
        {
            AsciiString usAscii = new AsciiString("NettyRocks");
            var         buf     = Unpooled.Buffer(16);

            buf.WriteBytes(Encoding.ASCII.GetBytes(usAscii.ToString()));
            var buf2 = Unpooled.Buffer(16);

            ByteBufferUtil.WriteAscii(buf2, usAscii);

            Assert.Equal(buf, buf2);

            buf.Release();
            buf2.Release();
        }
Exemple #6
0
        public static HttpMethod ValueOf(AsciiString name)
        {
            if (name != null)
            {
                HttpMethod result = ValueOfInline(name.Array);
                if (result != null)
                {
                    return(result);
                }

                // Fall back to slow path
                if (MethodMap.TryGetValue(name.ToString(), out result))
                {
                    return(result);
                }
            }
            // Really slow path and error handling
            return(new HttpMethod(name?.ToString()));
        }
Exemple #7
0
		public void GoToUrl (string url)
		{
			int index = -1;
			nsISHistory history;
			navigation.navigation.getSessionHistory(out history);
			int count = Count;
			nsIHistoryEntry entry;
			for (int i = 0; i < count; i++) {
				nsIURI uri;
				history.getEntryAtIndex(i, false, out entry);
				entry.getURI (out uri);
				AsciiString spec = new AsciiString(String.Empty);
				uri.getSpec (spec.Handle);
				if (string.Compare (spec.ToString (), url, true) == 0) {
					index = i;
					break;
				}
			}
			if (index > -1)
				this.GoToIndex (index);
		}
Exemple #8
0
        public static HttpMethod ValueOf(AsciiString name)
        {
            if (name is object)
            {
                HttpMethod result = ValueOfInline(name.Array);
                if (result is object)
                {
                    return(result);
                }

                // Fall back to slow path
                var methodName = name.ToString();
                if (MethodMap.TryGetValue(methodName, out result))
                {
                    return(result);
                }

                return(s_methodCache.GetOrAdd(methodName, s_convertToHttpMethodFunc));
            }
            // Really slow path and error handling
            return(new HttpMethod(name?.ToString()));
        }
Exemple #9
0
        public void SimpleRequestWithNoMatchingOrigin()
        {
            var           origin   = new AsciiString("http://localhost:8888");
            IHttpResponse response = SimpleRequest(CorsConfigBuilder.ForOrigins(
                                                       new AsciiString("https://localhost:8888")).Build(), origin.ToString());

            Assert.Null(response.Headers.Get(HttpHeaderNames.AccessControlAllowOrigin, null));
            Assert.Null(response.Headers.Get(HttpHeaderNames.AccessControlAllowHeaders, null));
            Assert.True(ReferenceCountUtil.Release(response));
        }
Exemple #10
0
        public void SimpleRequestWithOrigins()
        {
            var origin1 = new AsciiString("http://localhost:8888");
            var origin2 = new AsciiString("https://localhost:8888");

            ICharSequence[] origins   = { origin1, origin2 };
            IHttpResponse   response1 = SimpleRequest(CorsConfigBuilder.ForOrigins(origins).Build(), origin1.ToString());

            Assert.Equal(origin1, response1.Headers.Get(HttpHeaderNames.AccessControlAllowOrigin, null));
            Assert.Null(response1.Headers.Get(HttpHeaderNames.AccessControlAllowHeaders, null));
            Assert.True(ReferenceCountUtil.Release(response1));

            IHttpResponse response2 = SimpleRequest(CorsConfigBuilder.ForOrigins(origins).Build(), origin2.ToString());

            Assert.Equal(origin2, response2.Headers.Get(HttpHeaderNames.AccessControlAllowOrigin, null));
            Assert.Null(response2.Headers.Get(HttpHeaderNames.AccessControlAllowHeaders, null));
            Assert.True(ReferenceCountUtil.Release(response2));
        }
Exemple #11
0
 public WebSocketRequestBuilder Upgrade(AsciiString value)
 {
     this.upgrade = this.upgrade == null ? null : value.ToString();
     return(this);
 }
Exemple #12
0
 public override string ToString() => _value.ToString();
Exemple #13
0
        public void SimpleRequestWithOrigin()
        {
            var           origin   = new AsciiString("http://localhost:8888");
            IHttpResponse response = SimpleRequest(CorsConfigBuilder.ForOrigin(origin).Build(), origin.ToString());

            Assert.Equal(origin, response.Headers.Get(HttpHeaderNames.AccessControlAllowOrigin, null));
            Assert.Null(response.Headers.Get(HttpHeaderNames.AccessControlAllowHeaders, null));
        }