-
-
Notifications
You must be signed in to change notification settings - Fork 764
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f593eb2
commit 924838f
Showing
7 changed files
with
88 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/io/appium/java_client/internal/filters/AppiumHttp11EnforcerFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.appium.java_client.internal.filters; | ||
|
||
import org.openqa.selenium.remote.http.Filter; | ||
import org.openqa.selenium.remote.http.HttpHandler; | ||
|
||
import java.util.List; | ||
|
||
public class AppiumHttp11EnforcerFilter implements Filter { | ||
private static final List<String> HTTP2_UPGRADE_HEADERS = List.of( | ||
"Upgrade", "HTTP2-Settings", "Connection" | ||
); | ||
|
||
@Override | ||
public HttpHandler apply(HttpHandler next) { | ||
return req -> { | ||
var upgrade = req.getHeader("Upgrade"); | ||
if (upgrade != null && upgrade.trim().equalsIgnoreCase("h2c")) { | ||
HTTP2_UPGRADE_HEADERS.forEach(x -> req.removeHeader(x)); | ||
} | ||
return next.execute(req); | ||
}; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/io/appium/java_client/internal/filters/AppiumIdempotencyFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.appium.java_client.internal.filters; | ||
|
||
import org.openqa.selenium.remote.http.Filter; | ||
import org.openqa.selenium.remote.http.HttpHandler; | ||
import org.openqa.selenium.remote.http.HttpMethod; | ||
|
||
import java.util.UUID; | ||
|
||
public class AppiumIdempotencyFilter implements Filter { | ||
// https://github.com/appium/appium-base-driver/pull/400 | ||
private static final String IDEMPOTENCY_KEY_HEADER = "X-Idempotency-Key"; | ||
|
||
@Override | ||
public HttpHandler apply(HttpHandler next) { | ||
return req -> { | ||
if (req.getMethod() == HttpMethod.POST && req.getUri().endsWith("/session")) { | ||
req.setHeader(IDEMPOTENCY_KEY_HEADER, UUID.randomUUID().toString().toLowerCase()); | ||
} | ||
return next.execute(req); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/test/java/io/appium/java_client/internal/AppiumUserAgentFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters