Path: blob/trunk/javascript/selenium-webdriver/devtools/networkinterceptor.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.1617class HttpResponse {18/**19* Creates a HTTP Response that will be used to20* mock out network interceptions.21* @param {*} urlToIntercept22*/23constructor(urlToIntercept = '') {24this.returnBody = ''25this.returnHeaders = []26this.returnMethod = 'GET'27this.returnStatus = 20028this.urlToIntercept = urlToIntercept29}3031/**32* Add headers that will be returned when we intercept33* a HTTP Request34* @param {*} header35* @param {*} value36*/37addHeaders(header, value) {38this.returnHeaders.push({ name: header, value: value })39}4041get headers() {42return this.returnHeaders43}4445/**46* Set the STATUS value of the returned HTTP Request47* @param {*} value48*/49set status(value) {50// Add in check that his should be a number51this.returnStatus = value52}5354get status() {55return this.returnStatus56}5758/**59* Sets the value of the body of the HTTP Request that60* will be returned.61* @param {*} value62*/63set body(value) {64this.returnBody = value65}6667get body() {68let buff = Buffer.from(this.returnBody, 'utf-8')69return buff.toString('base64')70}7172/**73* Sets the method of the HTTP Request74* @param {*} value the method of the request.75*/76set method(value) {77this.returnMethod = value78}7980/**81* Returns the Method to be used in the intercept82*/83get method() {84return this.returnMethod85}86}8788exports.HttpResponse = HttpResponse899091