|
| 1 | +// Licensed to the Software Freedom Conservancy (SFC) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The SFC licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package org.openqa.selenium.bidi.network; |
| 19 | + |
| 20 | +import java.util.HashMap; |
| 21 | +import java.util.List; |
| 22 | +import java.util.Map; |
| 23 | +import java.util.stream.Collectors; |
| 24 | +import org.openqa.selenium.UsernameAndPassword; |
| 25 | + |
| 26 | +public class ContinueResponseParameters { |
| 27 | + private final Map<String, Object> map = new HashMap<>(); |
| 28 | + |
| 29 | + public ContinueResponseParameters(String request) { |
| 30 | + map.put("request", request); |
| 31 | + } |
| 32 | + |
| 33 | + public ContinueResponseParameters cookies(List<SetCookieHeader> cookieHeaders) { |
| 34 | + List<Map<String, Object>> cookies = |
| 35 | + cookieHeaders.stream().map(SetCookieHeader::toMap).collect(Collectors.toList()); |
| 36 | + map.put("cookies", cookies); |
| 37 | + return this; |
| 38 | + } |
| 39 | + |
| 40 | + public ContinueResponseParameters credentials(UsernameAndPassword credentials) { |
| 41 | + map.put( |
| 42 | + "credentials", Map.of("type", "password", credentials.password(), credentials.username())); |
| 43 | + return this; |
| 44 | + } |
| 45 | + |
| 46 | + public ContinueResponseParameters headers(List<Header> headers) { |
| 47 | + List<Map<String, Object>> headerList = |
| 48 | + headers.stream().map(Header::toMap).collect(Collectors.toList()); |
| 49 | + map.put("headers", headerList); |
| 50 | + return this; |
| 51 | + } |
| 52 | + |
| 53 | + public ContinueResponseParameters reasonPhrase(String reasonPhrase) { |
| 54 | + map.put("reasonPhrase", reasonPhrase); |
| 55 | + return this; |
| 56 | + } |
| 57 | + |
| 58 | + public ContinueResponseParameters statusCode(int statusCode) { |
| 59 | + map.put("statusCode", statusCode); |
| 60 | + return this; |
| 61 | + } |
| 62 | + |
| 63 | + public Map<String, Object> toMap() { |
| 64 | + return map; |
| 65 | + } |
| 66 | +} |
0 commit comments