mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Make curl go through corsproxy
This commit is contained in:
2 files changed
+11
-7
No files matched your search
@@ -76,7 +76,7 @@ describe('CurlCommand', () => {
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toBe('Hello World');
|
||||
expect(mockFetch).toHaveBeenCalledWith('https://example.com/', expect.objectContaining({
|
||||
expect(mockFetch).toHaveBeenCalledWith('https://corsproxy.io/?url=https%3A%2F%2Fexample.com%2F', expect.objectContaining({
|
||||
method: 'GET',
|
||||
headers: expect.objectContaining({
|
||||
'User-Agent': 'curl/8.0.0 (compatible; JavaScript fetch)'
|
||||
@@ -103,7 +103,7 @@ describe('CurlCommand', () => {
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toBe('{"success": true}');
|
||||
expect(mockFetch).toHaveBeenCalledWith('https://example.com/api', expect.objectContaining({
|
||||
expect(mockFetch).toHaveBeenCalledWith('https://corsproxy.io/?url=https%3A%2F%2Fexample.com%2Fapi', expect.objectContaining({
|
||||
method: 'POST',
|
||||
body: '{"name": "test"}',
|
||||
headers: expect.objectContaining({
|
||||
@@ -131,7 +131,7 @@ describe('CurlCommand', () => {
|
||||
], '/test');
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(mockFetch).toHaveBeenCalledWith('https://example.com/', expect.objectContaining({
|
||||
expect(mockFetch).toHaveBeenCalledWith('https://corsproxy.io/?url=https%3A%2F%2Fexample.com%2F', expect.objectContaining({
|
||||
headers: expect.objectContaining({
|
||||
'Authorization': 'Bearer token123',
|
||||
'Content-Type': 'application/json',
|
||||
@@ -245,7 +245,7 @@ describe('CurlCommand', () => {
|
||||
], '/test');
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(mockFetch).toHaveBeenCalledWith('https://example.com/', expect.objectContaining({
|
||||
expect(mockFetch).toHaveBeenCalledWith('https://corsproxy.io/?url=https%3A%2F%2Fexample.com%2F', expect.objectContaining({
|
||||
method: 'DELETE',
|
||||
headers: expect.objectContaining({
|
||||
'User-Agent': 'curl/8.0.0 (compatible; JavaScript fetch)'
|
||||
|
||||
@@ -59,6 +59,10 @@ export class CurlCommand implements ShellCommand {
|
||||
return createErrorResult(`${this.name}: unsupported protocol: ${url.protocol}`);
|
||||
}
|
||||
|
||||
// Proxy the URL through CorsProxy
|
||||
const originalUrl = url.toString();
|
||||
const proxiedUrl = `https://corsproxy.io/?url=${encodeURIComponent(originalUrl)}`;
|
||||
|
||||
// Prepare request
|
||||
const requestInit: RequestInit = {
|
||||
method: options.method,
|
||||
@@ -93,7 +97,7 @@ export class CurlCommand implements ShellCommand {
|
||||
|
||||
try {
|
||||
if (options.verbose && !options.silent) {
|
||||
console.log(`* Trying ${url.hostname}...`);
|
||||
console.log(`* Trying ${url.hostname}... (via CorsProxy)`);
|
||||
console.log(`> ${options.method} ${url.pathname}${url.search} HTTP/1.1`);
|
||||
console.log(`> Host: ${url.hostname}`);
|
||||
for (const [key, value] of Object.entries(options.headers)) {
|
||||
@@ -105,8 +109,8 @@ export class CurlCommand implements ShellCommand {
|
||||
}
|
||||
}
|
||||
|
||||
// Make the request
|
||||
const response = await fetch(url.toString(), requestInit);
|
||||
// Make the request using the proxied URL
|
||||
const response = await fetch(proxiedUrl, requestInit);
|
||||
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
Reference in new issue
Block a user