From 3ddd9b82a891e4d04b68e7f301bda44292a3c4af Mon Sep 17 00:00:00 2001 From: Tim Voronov Date: Sat, 27 Mar 2021 12:47:13 -0400 Subject: [PATCH] Bugfix/#597 headers panic (#602) * Remodeled HTTPHeaders * Remodeled HTTPCookies * Fixed cookie.Expires * Update documentation --- pkg/stdlib/html/document.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/stdlib/html/document.go b/pkg/stdlib/html/document.go index 312ddb96..a5c72fcd 100644 --- a/pkg/stdlib/html/document.go +++ b/pkg/stdlib/html/document.go @@ -26,8 +26,17 @@ type PageLoadParams struct { // @param {Int} [params.timeout=60000] - Page load timeout. // @param {String} [params.userAgent] - Custom user agent. // @param {Boolean} [params.keepCookies=False] - Boolean value indicating whether to use cookies from previous sessions i.e. not to open a page in the Incognito mode. -// @param {HTTPCookies} [params.cookies] - Set of HTTP cookies to use during page loading. -// @param {HTTPHeaders} [params.headers] - Set of HTTP headers to use during page loading. +// @param {Object[] | Object} [params.cookies] - Set of HTTP cookies to use during page loading. +// @param {String} params.cookies.*.name - Cookie name. +// @param {String} params.cookies.*.value - Cookie value. +// @param {String} params.cookies.*.path - Cookie path. +// @param {String} params.cookies.*.domain - Cookie domain. +// @param {Int} [params.cookies.*.maxAge] - Cookie max age. +// @param {String|DateTime} [params.cookies.*.expires] - Cookie expiration date time. +// @param {String} [params.cookies.*.sameSite] - Cookie cross-origin policy. +// @param {Boolean} [params.cookies.*.httpOnly=false] - Cookie cannot be accessed through client side script. +// @param {Boolean} [params.cookies.*.secure=false] - Cookie sent to the server only with an encrypted request over the HTTPS protocol. +// @param {Object} [params.headers] - Set of HTTP headers to use during page loading. // @param {Object} [params.ignore] - Set of parameters to ignore some page functionality or behavior. // @param {Object[]} [params.ignore.resources] - Collection of rules to ignore resources during page load and navigation. // @param {String} [params.ignore.resources.*.url] - Resource url pattern. If set, requests for matching urls will be blocked. Wildcards ('*' -> zero or more, '?' -> exactly one) are allowed. Escape character is backslash. Omitting is equivalent to "*". @@ -303,14 +312,14 @@ func parseCookie(value core.Value) (drivers.HTTPCookie, error) { expires, exists := co.Get("expires") if exists { - if err = core.ValidateType(maxAge, types.DateTime, types.String); err != nil { + if err = core.ValidateType(expires, types.DateTime, types.String); err != nil { return drivers.HTTPCookie{}, err } if expires.Type() == types.DateTime { cookie.Expires = expires.(values.DateTime).Unwrap().(time.Time) } else { - t, err := time.Parse(expires.String(), values.DefaultTimeLayout) + t, err := time.Parse(values.DefaultTimeLayout, expires.String()) if err != nil { return drivers.HTTPCookie{}, err