Module org.htmlunit

Class Headers

java.lang.Object
org.htmlunit.corejs.javascript.SlotMapOwner<org.htmlunit.corejs.javascript.Scriptable>
org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.javascript.HtmlUnitScriptable
org.htmlunit.javascript.host.fetch.Headers
All Implemented Interfaces:
Serializable, Cloneable, org.htmlunit.corejs.javascript.ConstProperties<org.htmlunit.corejs.javascript.Scriptable>, org.htmlunit.corejs.javascript.debug.DebuggableObject, org.htmlunit.corejs.javascript.PropHolder<org.htmlunit.corejs.javascript.Scriptable>, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.SymbolScriptable

public class Headers extends HtmlUnitScriptable
A JavaScript object for Headers.
Author:
Ahmed Ashour, Ronald Brill
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    The guard of a headers object; determines which changes are allowed.
    static final class 
    ES6Iterator implementation for the iterators of Headers.

    Nested classes/interfaces inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    org.htmlunit.corejs.javascript.ScriptableObject.DescriptorInfo, org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator, org.htmlunit.corejs.javascript.ScriptableObject.LambdaGetterFunction, org.htmlunit.corejs.javascript.ScriptableObject.LambdaSetterFunction
  • Field Summary

    Fields inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    CONST, DONTENUM, EMPTY, LEGACY_CONST, PERMANENT, READONLY, STRICTLY_READONLY, UNINITIALIZED_CONST

    Fields inherited from class org.htmlunit.corejs.javascript.SlotMapOwner

    isSealed

    Fields inherited from interface org.htmlunit.corejs.javascript.Scriptable

    NOT_FOUND
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    append(org.htmlunit.corejs.javascript.Context cx, org.htmlunit.corejs.javascript.VarScope scope, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function funObj)
    Appends a new value to an existing header, or adds the header if it does not exist.
    void
    appendHeader(String name, String value)
    Appends a header after normalizing and validating name and value.
    void
    Deletes all values of a header.
    org.htmlunit.corejs.javascript.ES6Iterator
    Returns an iterator over all name/value pairs (sorted, combined; the names in lower case).
    void
    forEach(Object callback, Object thisArg)
    Calls the callback for every header (sorted, combined; the names in lower case).
    Returns the guard.
    Returns the combined values of a header.
    Returns the header list (the names as given).
    org.htmlunit.corejs.javascript.Scriptable
    Returns the values of all Set-Cookie headers.
    static boolean
    isForbiddenRequestHeader(String name, String value, BrowserVersion browserVersion)
    INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
    Returns whether the header is a forbidden request header; used by fetch() and by XMLHttpRequest.
    static Headers
    jsConstructor(org.htmlunit.corejs.javascript.Context cx, org.htmlunit.corejs.javascript.VarScope scope, Object[] args, org.htmlunit.corejs.javascript.Function ctorObj, boolean inNewExpr)
    JavaScript constructor.
    static void
    jsDelete(org.htmlunit.corejs.javascript.Context cx, org.htmlunit.corejs.javascript.VarScope scope, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function funObj)
    Deletes a header.
    static String
    jsGet(org.htmlunit.corejs.javascript.Context cx, org.htmlunit.corejs.javascript.VarScope scope, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function funObj)
    Returns the combined values of a header.
    static boolean
    jsHas(org.htmlunit.corejs.javascript.Context cx, org.htmlunit.corejs.javascript.VarScope scope, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function funObj)
    Returns whether a header exists.
    static void
    jsSet(org.htmlunit.corejs.javascript.Context cx, org.htmlunit.corejs.javascript.VarScope scope, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function funObj)
    Sets the value of a header (replaces all existing values), or adds the header if it does not exist.
    org.htmlunit.corejs.javascript.ES6Iterator
    Returns an iterator over all names (sorted, in lower case).
    void
    Sets the guard.
    void
    setHeader(String name, String value)
    Sets a header after normalizing and validating name and value.
    org.htmlunit.corejs.javascript.ES6Iterator
    Returns an iterator over all values (sorted by the names, combined).

    Methods inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    applyDescriptorToAttributeBitset, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkNotSealed, checkPropertyChangeForSlot, checkPropertyChangeForSlot, checkPropertyDefinition, checkPropertyDefinition, checkSlotRemoval, defineBuiltinProperty, defineBuiltinProperty, defineBuiltInProperty, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureScriptableObjectButNotSymbol, ensureSymbolScriptable, ensureType, get, get, getAllIds, getAncestor, getArrayPrototype, getClassPrototype, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getObjectPrototype, getParentScope, getProperty, getProperty, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getSuperProperty, getSuperProperty, getSuperProperty, getThis, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, hasProperty, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGenericDescriptor, isGetterOrSetter, isGetterOrSetter, isTrue, preventExtensions, put, put, putConst, putConstProperty, putConstProperty, putOwnProperty, putOwnProperty, putOwnProperty, putProperty, putProperty, putProperty, putProperty, putSuperProperty, putSuperProperty, putSuperProperty, querySlot, redefineProperty, redefineProperty, sameValue, sealObject, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, size

    Methods inherited from class org.htmlunit.corejs.javascript.SlotMapOwner

    associateValue, checkNotSealed, copyAssociatedValue, createSlotMap, createSlotMap, defineProperty, defineProperty, get, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getIds, has, has, isSealed, readMaps, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, writeMaps

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.htmlunit.corejs.javascript.Scriptable

    get, getIds, has, has

    Methods inherited from interface org.htmlunit.corejs.javascript.SymbolScriptable

    get, has
  • Constructor Details

    • Headers

      public Headers()
      Default constructor.
  • Method Details

    • jsConstructor

      public static Headers jsConstructor(org.htmlunit.corejs.javascript.Context cx, org.htmlunit.corejs.javascript.VarScope scope, Object[] args, org.htmlunit.corejs.javascript.Function ctorObj, boolean inNewExpr)
      JavaScript constructor.
      Parameters:
      cx - the current context
      scope - the scope
      args - the arguments (the optional initial headers: a Headers object, a sequence of name/value pairs or a record)
      ctorObj - the function object
      inNewExpr - whether invoked via new
      Returns:
      the new Headers instance
    • append

      public static void append(org.htmlunit.corejs.javascript.Context cx, org.htmlunit.corejs.javascript.VarScope scope, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function funObj)
      Appends a new value to an existing header, or adds the header if it does not exist.
      Parameters:
      cx - the current context
      scope - the scope
      thisObj - this object
      args - the arguments (name and value)
      funObj - the function
    • jsSet

      public static void jsSet(org.htmlunit.corejs.javascript.Context cx, org.htmlunit.corejs.javascript.VarScope scope, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function funObj)
      Sets the value of a header (replaces all existing values), or adds the header if it does not exist.
      Parameters:
      cx - the current context
      scope - the scope
      thisObj - this object
      args - the arguments (name and value)
      funObj - the function
    • jsDelete

      public static void jsDelete(org.htmlunit.corejs.javascript.Context cx, org.htmlunit.corejs.javascript.VarScope scope, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function funObj)
      Deletes a header.
      Parameters:
      cx - the current context
      scope - the scope
      thisObj - this object
      args - the arguments (name)
      funObj - the function
    • jsGet

      public static String jsGet(org.htmlunit.corejs.javascript.Context cx, org.htmlunit.corejs.javascript.VarScope scope, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function funObj)
      Returns the combined values of a header.
      Parameters:
      cx - the current context
      scope - the scope
      thisObj - this object
      args - the arguments (name)
      funObj - the function
      Returns:
      the values separated by ', ' or null if the header does not exist
    • jsHas

      public static boolean jsHas(org.htmlunit.corejs.javascript.Context cx, org.htmlunit.corejs.javascript.VarScope scope, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function funObj)
      Returns whether a header exists.
      Parameters:
      cx - the current context
      scope - the scope
      thisObj - this object
      args - the arguments (name)
      funObj - the function
      Returns:
      whether the header exists
    • getSetCookie

      public org.htmlunit.corejs.javascript.Scriptable getSetCookie()
      Returns the values of all Set-Cookie headers.
      Returns:
      the values
    • forEach

      public void forEach(Object callback, Object thisArg)
      Calls the callback for every header (sorted, combined; the names in lower case).
      Parameters:
      callback - the function to call with the value, the name and this object
      thisArg - the value to use as this for the callback
    • entries

      public org.htmlunit.corejs.javascript.ES6Iterator entries()
      Returns an iterator over all name/value pairs (sorted, combined; the names in lower case).
      Returns:
      the iterator
    • keys

      public org.htmlunit.corejs.javascript.ES6Iterator keys()
      Returns an iterator over all names (sorted, in lower case).
      Returns:
      the iterator
    • values

      public org.htmlunit.corejs.javascript.ES6Iterator values()
      Returns an iterator over all values (sorted by the names, combined).
      Returns:
      the iterator
    • appendHeader

      public void appendHeader(String name, String value)
      Appends a header after normalizing and validating name and value.
      Parameters:
      name - the name
      value - the value
      See Also:
    • setHeader

      public void setHeader(String name, String value)
      Sets a header after normalizing and validating name and value.
      Parameters:
      name - the name
      value - the value
      See Also:
    • deleteHeader

      public void deleteHeader(String name)
      Deletes all values of a header.
      Parameters:
      name - the name
    • getHeader

      public String getHeader(String name)
      Returns the combined values of a header.
      Parameters:
      name - the name
      Returns:
      the values separated by ', ' or null if the header does not exist
    • getHeaderList

      public List<NameValuePair> getHeaderList()
      Returns the header list (the names as given).
      Returns:
      the header list
    • getGuard

      public Headers.Guard getGuard()
      Returns the guard.
      Returns:
      the guard
    • setGuard

      public void setGuard(Headers.Guard guard)
      Sets the guard.
      Parameters:
      guard - the guard
    • isForbiddenRequestHeader

      public static boolean isForbiddenRequestHeader(String name, String value, BrowserVersion browserVersion)
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Returns whether the header is a forbidden request header; used by fetch() and by XMLHttpRequest.

      Forbidden are the names of the list of the Fetch standard, the names starting with 'proxy-' or 'sec-' and the method override headers (X-HTTP-Method, X-HTTP-Method-Override, X-Method-Override) if one of the values is a forbidden method (CONNECT, TRACE, TRACK).

      Like Chrome/Edge, the User-Agent header is forbidden also (feature JS_REQUEST_HEADER_USER_AGENT_FORBIDDEN).
      Parameters:
      name - the name
      value - the value
      browserVersion - the browser version
      Returns:
      whether the header is a forbidden request header
      See Also: