@haxall/haxall
    Preparing search index...

    Class WebUtil

    WebUtil encapsulates several useful utility web methods. Also see sys::MimeType and its utility methods.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    type$: Type

    Methods

    • Return a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object:

      this < that   =>  <0
      this == that => 0
      this > that => >0

      This method may also be accessed via the < <= <=> >= and > shortcut operators. If not overridden the default implementation compares the toStr representations. Also see docLang.

      Examples:

      3.compare(8)  =>  -1
      8.compare(3) => 1
      8.compare(8) => 0
      3 <=> 8 => -1 // shortcut for 3.compare(8)

      Parameters

      Returns number

    • Compare this object to the specified for equality. This method may be accessed via the == and != shortcut operators. If not overridden the default implementation compares for reference equality using the === operator. If this method is overridden, then hash() must also be overridden such that any two objects which return true for equals() must return the same value for hash(). This method must accept null and return false.

      Parameters

      Returns boolean

    • Return a unique hashcode for this object. If a class overrides hash() then it must ensure if equals() returns true for any two objects then they have same hash code.

      Returns number

    • Return if this Obj is immutable and safe to share between threads:

      • an instance of a const class
      • the result of toImmutable on List, Map, or Buf
      • a Func object may or may not be immutable - see sys::Func.
      • other instances are assumed mutable and return false

      Returns boolean

    • Get an immutable representation of this instance or throw NotImmutableErr if this object cannot be represented as an immutable:

      • if type is const, return this
      • if already an immutable List, Map, Buf, or Func return this
      • if a List, then attempt to perform a deep clone by calling toImmutable on all items
      • if a Map, then attempt to perform a deep clone by calling toImmutable on all values (keys are already immutable)
      • some Funcs can be made immutable - see sys::Func
      • if a Buf create immutable copy, see sys::Buf
      • any other object throws NotImmutableErr

      Returns Readonly<this>

    • Return a string representation of this object.

      Returns string

    • Trap a dynamic call for handling. Dynamic calls are invoked with the -> shortcut operator:

      a->x        a.trap("x", null)
      a->x() a.trap("x", null)
      a->x = b a.trap("x", [b])
      a->x(b) a.trap("x", [b])
      a->x(b, c) a.trap("x", [b, c])

      The default implementation provided by Obj attempts to use reflection. If name maps to a method, it is invoked with the specified arguments. If name maps to a field and args.size is zero, get the field. If name maps to a field and args.size is one, set the field and return args[0]. Otherwise throw UnknownSlotErr.

      Parameters

      Returns JsObj

    • Get the Type instance which represents this object's class. Also seeType.of or Pod.of.

      Returns Type

    • This method called whenever an it-block is applied to an object. The default implementation calls the function with this, and then returns this.

      Parameters

      • f: (arg0: this) => void

      Returns this

    • Write x.toStr to standard output followed by newline. If x is null then print "null". If no argument is provided then print an empty line.

      Parameters

      Returns void

    • Decode a HTTP quoted string according to RFC 2616 Section 2.2. The given string must be wrapped in quotes. See toQuotedStr.

      Parameters

      • s: string

      Returns string

    • Given a set of HTTP headers map Content-Type to its charset or default to UTF-8.

      Parameters

      • headers: Map<string, string>

      Returns Charset

    • Return if the specified string is a valid HTTP token production which is any ASCII character which is not a control char or a separator. The separators characters are:

      "(" | ")" | "<" | ">" | "@" |
      "," | ";" | ":" | "\" | <"> |
      "/" | "[" | "]" | "?" | "=" |
      "{" | "}" | SP | HT

      Parameters

      • s: string

      Returns boolean

    • Return if given char unicode point is allowable within the HTTP token production. See isToken.

      Parameters

      • c: number

      Returns boolean

    • Generate the method invocation code used to boostrap into JavaScript from a webpage. This must be called inside the <head> tag for the page. The main method will be invoked using the onLoad DOM event.

      The main argument can be either a type or method. If no method is specified, main is used. If the method is not static, a new instance of type is created:

      "foo::Instance"     =>  Instance().main()
      "foo::Instance.bar" => Instance().bar()
      "foo::Static" => Static.main()
      "foo::Static.bar" => Static.bar()

      If env is specified, then vars will be added to and available from sys::Env.vars on client-side.

      Parameters

      Returns void

    • Parameters

      • ...args: unknown[]

      Returns WebUtil

    • Wrap the given input stream to read bytes using a HTTP chunked transfer encoding. The wrapped streams provides a contiguous stream of bytes until the last chunk is read. Closing the wrapper stream does not close the underlying stream.

      Parameters

      Returns InStream

    • Wrap the given output stream to write bytes using a HTTP chunked transfer encoding. Closing the wrapper stream terminates the chunking, but does not close the underlying stream.

      Parameters

      Returns OutStream

    • Given a set of headers, wrap the specified input stream to read the content body:

      1. If Content-Encoding is gzip then wrap via sys::Zip.gzipInStream
      2. If Content-Length then makeFixedInStream
      3. If Transfer-Encoding is chunked then makeChunkedInStream
      4. If Content-Type assume non-pipelined connection and return in directly

      If a stream is returned, then it is automatically configured with the correct content encoding based on the Content-Type.

      Parameters

      Returns InStream

    • Given a set of headers, wrap the specified output stream to write the content body:

      1. If Content-Length then makeFixedOutStream
      2. If Content-Type then set Transfer-Encoding header to chunked and return makeChunkedOutStream
      3. Assume no content and return null

      If a stream is returned, then it is automatically configured with the correct content encoding based on the Content-Type.

      Parameters

      Returns OutStream

    • Wrap the given input stream to read a fixed number of bytes. Once fixed bytes have been read from the underlying input stream, the wrapped stream will return end-of-stream. Closing the wrapper stream does not close the underlying stream.

      Parameters

      Returns InStream

    • Wrap the given output stream to write a fixed number of bytes. Once fixed bytes have been written, attempting to further bytes will throw IOErr. Closing the wrapper stream does not close the underlying stream.

      Parameters

      Returns OutStream

    • Parse a series of HTTP headers according to RFC 2616 section 4.2. The final CRLF which terminates headers is consumed with the stream positioned immediately following. The headers are returned as a case insensitive map. Throw ParseErr if headers are malformed.

      Parameters

      Returns Map<string, string>

    • Parse a list of comma separated tokens. Any leading or trailing whitespace is trimmed from the list of tokens.

      Parameters

      • s: string

      Returns List<string>

    • Parse a multipart/form-data input stream. For each part in the stream call the given callback function with the part's headers and an input stream used to read the part's body. Each callback must completely drain the input stream to prepare for the next part. Also see WebReq.parseMultiPartForm.

      Parameters

      Returns void

    • Given an HTTP header that uses q values, return a map of name/q-value pairs. This map has a def value of 0.

      Example:

      compress,gzip              =>  ["compress":1f, "gzip":1f]
      compress;q=0.5,gzip;q=0.0 => ["compress":0.5f, "gzip":0.0f]

      Parameters

      • s: string

      Returns Map<string, number>

    • Return the specified string as a HTTP quoted string according to RFC 2616 Section 2.2. The result is wrapped in quotes. Throw ArgErr if any character is outside of the ASCII range of 0x20 to 0x7e. The quote char itself is backslash escaped. See fromQuotedStr.

      Parameters

      • s: string

      Returns string