Skip to content

Commit

Permalink
chore(config): add redirect_policy types
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Sep 14, 2024
1 parent 2685222 commit 1a79f13
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 191 deletions.
2 changes: 1 addition & 1 deletion cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions javascript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion javascript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@spider-cloud/spider-client",
"version": "0.0.69",
"version": "0.0.70",
"description": "Isomorphic Javascript SDK for Spider Cloud services",
"scripts": {
"test": "node --import tsx --test __tests__/*test.ts",
Expand Down
11 changes: 11 additions & 0 deletions javascript/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ export type WebAutomationMap = Record<string, WebAutomation[]>;
// Map execution scripts for paths or urls.
export type ExecutionScriptsMap = Record<string, string>;

// The HTTP redirect policy to use. Loose allows all domains and Strict only allows relative requests to the domain.
export enum RedirectPolicy {
Loose = "Loose",
Strict = "Strict",
}

/**
* Represents the options available for making a spider request.
*/
Expand Down Expand Up @@ -383,6 +389,11 @@ export interface SpiderParams {
* Perform custom Javascript tasks on a url or url path. You need to make your `request` `chrome` or `smart`.
*/
execution_scripts?: ExecutionScriptsMap;

/**
* The redirect policy for HTTP request. Set the value to Loose to allow all.
*/
redirect_policy?: RedirectPolicy;
}

// Core actions response type.
Expand Down
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def read_file(fname):

setup(
name="spider-client",
version="0.0.69",
version="0.0.70",
url="https://github.com/spider-rs/spider-clients/tree/main/python",
author="Spider",
author_email="[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion python/spider/async_spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def _prepare_headers(
return {
"Content-Type": content_type,
"Authorization": f"Bearer {self.api_key}",
"User-Agent": "AsyncSpider-Client/0.0.69",
"User-Agent": "AsyncSpider-Client/0.0.70",
}

async def _handle_error(self, response: ClientResponse, action: str) -> None:
Expand Down
2 changes: 1 addition & 1 deletion python/spider/spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def _prepare_headers(self, content_type: str = "application/json"):
return {
"Content-Type": content_type,
"Authorization": f"Bearer {self.api_key}",
"User-Agent": f"Spider-Client/0.0.69",
"User-Agent": f"Spider-Client/0.0.70",
}

def _post_request(self, url: str, data, headers, stream=False):
Expand Down
8 changes: 7 additions & 1 deletion python/spider/spider_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ class InfiniteScroll:
WebAutomationMap = Dict[str, List[WebAutomation]]
ExecutionScriptsMap = Dict[str, str]

RedirectPolicy = Literal[
"Loose",
"Strict"
]

@dataclass
class QueryRequest:
url: Optional[str] = field(default=None)
Expand Down Expand Up @@ -261,6 +266,7 @@ class RequestParamsDict(TypedDict, total=False):

# Perform custom web automated tasks on a url or url path. You need to make your `request` `chrome` or `smart`.
automation_scripts: Optional[WebAutomationMap]

# The redirect policy for HTTP request. Set the value to Loose to allow all.
redirect_policy: Optional[RedirectPolicy]

JsonCallback = Callable[[dict], None]
Loading

0 comments on commit 1a79f13

Please sign in to comment.