How to use CheckOriginHeader class of org.openqa.selenium.grid.web package

Best Selenium code snippet using org.openqa.selenium.grid.web.CheckOriginHeader

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
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
18package org.openqa.selenium.grid.server;
19
20import com.google.common.collect.ImmutableList;
21import com.google.common.collect.ImmutableSet;
22import org.openqa.selenium.grid.config.Config;
23import org.openqa.selenium.grid.web.CheckContentTypeHeader;
24import org.openqa.selenium.grid.web.CheckOriginHeader;
25import org.openqa.selenium.grid.web.EnsureSpecCompliantResponseHeaders;
26import org.openqa.selenium.internal.Require;
27import org.openqa.selenium.remote.http.Filter;
28import org.openqa.selenium.remote.http.HttpClient;
29import org.openqa.selenium.remote.tracing.TracedHttpClient;
30import org.openqa.selenium.remote.tracing.Tracer;
31
32import java.util.List;
33import java.util.Optional;
34import java.util.Set;
35
36public class NetworkOptions {
37
38  private static final String NETWORK_SECTION = "network";
39
40  private final Config config;
41  // These are commonly used by process which can't set various headers.
42  private final Set<String> SKIP_CHECKS_ON = ImmutableSet.of("/status", "/readyz");
43
44  public NetworkOptions(Config config) {
45    this.config = Require.nonNull("Config", config);
46  }
47
48  public HttpClient.Factory getHttpClientFactory(Tracer tracer) {
49    return new TracedHttpClient.Factory(tracer, HttpClient.Factory.createDefault());
50  }
51
52  public Filter getSpecComplianceChecks() {
53    // Base case: we do nothing
54    Filter toReturn = httpHandler -> httpHandler;
55
56    toReturn = toReturn.andThen(new EnsureSpecCompliantResponseHeaders());
57
58    if (config.getBool(NETWORK_SECTION, "relax-checks").orElse(false)) {
59      return toReturn;
60    }
61
62    if (config.getBool(NETWORK_SECTION, "check_content_type").orElse(true)) {
63      toReturn = toReturn.andThen(new CheckContentTypeHeader(SKIP_CHECKS_ON));
64    }
65
66    boolean checkOrigin = config.getBool(NETWORK_SECTION, "check_origin_header").orElse(true);
67    Optional<List<String>> allowedOrigins = config.getAll(NETWORK_SECTION, "allowed_origins");
68
69    if (checkOrigin || allowedOrigins.isPresent()) {
70      toReturn = toReturn.andThen(new CheckOriginHeader(allowedOrigins.orElse(ImmutableList.of()), SKIP_CHECKS_ON));
71    }
72
73    return toReturn;
74  }
75}
76
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

...Most popular Stackoverflow questions on CheckOriginHeader

    No relevant questions found for this class 😞

Most used methods in CheckOriginHeader

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)