Path: blob/trunk/javascript/selenium-webdriver/bidi/continueRequestParameters.js
2884 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617const { BytesValue, Header } = require('./networkTypes')1819/**20* Represents the parameters for a continue request command.21* Described in https://w3c.github.io/webdriver-bidi/#command-network-continueRequest.22*/23class ContinueRequestParameters {24#map = new Map()2526constructor(request) {27this.#map.set('request', request)28}2930/**31* Sets the body value for the request.32*33* @param {BytesValue} value - The value to set as the body. Must be an instance of BytesValue.34* @returns {ContinueRequestParameters} - The current instance of the ContinueRequestParameters for chaining.35* @throws {Error} - If the value is not an instance of BytesValue.36*/37body(value) {38if (!(value instanceof BytesValue)) {39throw new Error(`Value must be an instance of BytesValue. Received: '${value})'`)40}41this.#map.set('body', Object.fromEntries(value.asMap()))42return this43}4445/**46* Sets the cookies for the request.47*48* @param {Header[]} cookieHeaders - An array of cookie headers.49* @returns {ContinueRequestParameters} - The current instance of the ContinueRequestParameters for chaining.50* @throws {Error} - If a cookie header is not an instance of Header.51*/52cookies(cookieHeaders) {53const cookies = []54cookieHeaders.forEach((header) => {55if (!(header instanceof Header)) {56throw new Error(`CookieHeader must be an instance of Header. Received:'${header}'`)57}58cookies.push(Object.fromEntries(header.asMap()))59})6061this.#map.set('cookies', cookies)62return this63}6465/**66* Sets the headers for the request.67*68* @param {Header[]} headers - An array of Header objects.69* @returns {ContinueRequestParameters} - The current instance of the ContinueRequestParameters for chaining.70* @throws {Error} - If the header value is not an instance of Header.71*/72headers(headers) {73const headerList = []74headers.forEach((header) => {75if (!(header instanceof Header)) {76throw new Error(`Header value must be an instance of Header. Received:'${header}'`)77}78headerList.push(Object.fromEntries(header.asMap()))79})8081this.#map.set('headers', headerList)82return this83}8485/**86* Sets the HTTP method for the request.87*88* @param {string} method - The HTTP method to be set.89* @returns {ContinueRequestParameters} - The updated `continueRequestParameters` object.90* @throws {Error} - If the method parameter is not a string.91*/92method(method) {93if (typeof method !== 'string') {94throw new Error(`Http method must be a string. Received: '${method})'`)95}96this.#map.set('method', method)97return this98}99100/**101* Sets the URL for the request.102*103* @param {string} url - The URL to set for the request.104* @returns {ContinueRequestParameters} - The current instance of the ContinueRequestParameters for chaining.105* @throws {Error} - If the url parameter is not a string.106*/107url(url) {108if (typeof url !== 'string') {109throw new Error(`Url must be a string. Received:'${url}'`)110}111112this.#map.set('url', url)113return this114}115116asMap() {117return this.#map118}119}120121module.exports = { ContinueRequestParameters }122123124