예제 #1
0
        public static void GetEncoding(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            Encoding encoding = NSJSEncoding.DefaultEncoding;

            if (arguments.Length > 0)
            {
                string path = (arguments[0] as NSJSString)?.Value;
                if (path != null)
                {
                    encoding = GetEncoding(path);
                }
                else
                {
                    byte[] buffer = (arguments[0] as NSJSUInt8Array)?.Buffer;
                    int    offset = 0;
                    if (buffer != null && arguments.Length > 1)
                    {
                        NSJSInt32 i = arguments[1] as NSJSInt32;
                        offset = (i == null ? 0x00 : i.Value);
                    }
                    encoding = GetEncoding(buffer, offset);
                }
            }
            arguments.SetReturnValue(NSJSEncoding.New(arguments.VirtualMachine, encoding));
        }
예제 #2
0
        private static void ContentEncoding(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            HTTPResponse             response  = GetResponse(arguments.This);

            if (response == null)
            {
                Throwable.ObjectDisposedException(arguments.VirtualMachine);
            }
            else
            {
                NSJSVirtualMachine machine = arguments.VirtualMachine;
                if (arguments.Length <= 0)
                {
                    arguments.SetReturnValue(NSJSEncoding.New(machine, response.ContentEncoding));
                }
                else
                {
                    var encoding = NSJSEncoding.GetEncoding(arguments[0] as NSJSObject);
                    if (encoding == null)
                    {
                        encoding = NSJSEncoding.DefaultEncoding;
                    }
                    response.ContentEncoding = encoding;
                    arguments.SetReturnValue(true);
                }
            }
        }
예제 #3
0
        public static NSJSObject New(NSJSVirtualMachine machine, NSJSObject context, HTTPRequest request)
        {
            if (machine == null || context == null || request == null)
            {
                return(null);
            }
            NSJSObject objective = NSJSObject.New(machine);

            objective.Set("HttpMethod", request.HttpMethod);
            objective.Set("IsLocal", request.IsLocal);
            objective.Set("KeepAlive", request.KeepAlive);
            objective.Set("ContentType", request.ContentType);
            objective.Set("CurrentContext", context);
            objective.Set("Files", ObjectAuxiliary.ToObject(machine, request.Files));
            objective.Set("InputStream", NSJSValue.NullMerge(machine, NSJSStream.New(machine, request.InputStream)));
            objective.Set("Cookies", ArrayAuxiliary.ToArray(machine, request.Cookies));
            objective.Set("RequestTraceIdentifier", request.RequestTraceIdentifier.ToString()); // "D"
            objective.Set("RemoteEndPoint", ObjectAuxiliary.ToObject(machine, request.RemoteEndPoint));
            objective.Set("ContentEncoding", NSJSEncoding.New(machine, request.ContentEncoding ?? NSJSEncoding.DefaultEncoding));
            objective.Set("Form", ObjectAuxiliary.ToObject(machine, request.Form));
            objective.Set("QueryString", ObjectAuxiliary.ToObject(machine, request.QueryString));
            objective.Set("ContentLength", Convert.ToDouble(request.ContentLength));
            objective.Set("AcceptTypes", ArrayAuxiliary.ToArray(machine, request.AcceptTypes));
            objective.Set("Path", request.Path);
            objective.Set("RawUrl", request.RawUrl);
            objective.Set("ServiceName", request.ServiceName);
            objective.Set("Url", request.Url?.ToString());
            objective.Set("UrlReferrer", request.UrlReferrer?.ToString());
            objective.Set("UserAgent", request.UserAgent);
            objective.Set("UserHostAddress", request.UserHostAddress);
            objective.Set("UserHostName", request.UserHostName);
            objective.Set("ProtocolVersion", request.ProtocolVersion.ToString());
            objective.Set("LocalEndPoint", ObjectAuxiliary.ToObject(machine, request.LocalEndPoint));
            objective.Set("UserLanguages", ArrayAuxiliary.ToArray(machine, request.UserLanguages));
            return(objective);
        }