mirror of
https://github.com/curlconverter/curlconverter.git
synced 2022-05-22 02:35:29 +03:00
Always add scheme to URL (#397)
This commit is contained in:
committed by
GitHub
parent
5747e27754
commit
afba7f2413
@@ -232,14 +232,7 @@ export const _toElixir = (
|
||||
warnings?: Warnings
|
||||
): [string, Warnings] => {
|
||||
warnings = warnings || [];
|
||||
// curl automatically prepends 'http' if the scheme is missing, but python fails and returns an error
|
||||
// we tack it on here to mimic curl
|
||||
if (!request.url.match(/https?:/)) {
|
||||
request.url = "http://" + request.url;
|
||||
}
|
||||
if (!request.urlWithoutQuery.match(/https?:/)) {
|
||||
request.urlWithoutQuery = "http://" + request.urlWithoutQuery;
|
||||
}
|
||||
|
||||
if (request.cookies) {
|
||||
util.deleteHeader(request, "cookie");
|
||||
}
|
||||
|
||||
@@ -125,14 +125,6 @@ export const _toJsonString = (
|
||||
warnings?: Warnings
|
||||
): [string, Warnings] => {
|
||||
warnings = warnings || [];
|
||||
// curl automatically prepends 'http' if the scheme is missing, but python fails and returns an error
|
||||
// we tack it on here to mimic curl
|
||||
if (!request.url.match(/https?:/)) {
|
||||
request.url = "http://" + request.url;
|
||||
}
|
||||
if (!request.urlWithoutQuery.match(/https?:/)) {
|
||||
request.urlWithoutQuery = "http://" + request.urlWithoutQuery;
|
||||
}
|
||||
|
||||
const requestJson: JSONOutput = {
|
||||
url: (request.queryDict ? request.urlWithoutQuery : request.url).replace(
|
||||
|
||||
@@ -864,16 +864,6 @@ export const _toPython = (
|
||||
headerDict += "}\n";
|
||||
}
|
||||
|
||||
// curl automatically prepends 'http' if the scheme is missing, but python fails and returns an error
|
||||
// we tack it on here to mimic curl
|
||||
// TODO: warn users about unsupported schemes
|
||||
if (!request.url.match(/https?:/)) {
|
||||
request.url = "http://" + request.url;
|
||||
}
|
||||
if (!request.urlWithoutQuery.match(/https?:/)) {
|
||||
request.urlWithoutQuery = "http://" + request.urlWithoutQuery;
|
||||
}
|
||||
|
||||
let requestLine;
|
||||
if (
|
||||
["GET", "HEAD", "POST", "PATCH", "PUT", "DELETE", "OPTIONS"].includes(
|
||||
|
||||
@@ -159,14 +159,6 @@ export const _toR = (
|
||||
} else if (request.multipartUploads) {
|
||||
filesString = getFilesString(request);
|
||||
}
|
||||
// curl automatically prepends 'http' if the scheme is missing, but rstats fails and returns an error
|
||||
// we tack it on here to mimic curl
|
||||
if (!request.url.match(/https?:/)) {
|
||||
request.url = "http://" + request.url;
|
||||
}
|
||||
if (!request.urlWithoutQuery.match(/https?:/)) {
|
||||
request.urlWithoutQuery = "http://" + request.urlWithoutQuery;
|
||||
}
|
||||
const url = request.queryDict ? request.urlWithoutQuery : request.url;
|
||||
|
||||
let requestLine = "res <- httr::";
|
||||
|
||||
@@ -101,9 +101,6 @@ export const _toStrest = (
|
||||
if (request.insecure) {
|
||||
response.allowInsecure = true;
|
||||
}
|
||||
if (!request.urlWithoutQuery.match(/https?:/)) {
|
||||
request.urlWithoutQuery = "http://" + request.urlWithoutQuery;
|
||||
}
|
||||
response.requests = {
|
||||
curl_converter: {
|
||||
request: {
|
||||
|
||||
21
src/util.ts
21
src/util.ts
@@ -1451,6 +1451,27 @@ function buildRequest(
|
||||
method = "POST";
|
||||
}
|
||||
|
||||
// curl automatically prepends 'http' if the scheme is missing,
|
||||
// but many libraries fail if your URL doesn't have it,
|
||||
// we tack it on here to mimic curl
|
||||
//
|
||||
// RFC 3986 3.1 says
|
||||
// scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
|
||||
// but curl will accept a digit/plus/minus/dot in the first character
|
||||
// curl will also accept a url with one / like http:/localhost
|
||||
const schemeMatch = url.match(/^([a-zA-Z0-9+-.]*):\/\/?/);
|
||||
if (schemeMatch) {
|
||||
const scheme = schemeMatch[1].toLowerCase();
|
||||
if (scheme !== "http" && scheme !== "https") {
|
||||
warnings.push(["bad-scheme", `Protocol "${scheme}" not supported`]);
|
||||
}
|
||||
url = scheme + "://" + url.slice(schemeMatch[0].length);
|
||||
} else {
|
||||
// curl's default scheme is actually https://
|
||||
// but we don't do that because, unlike curl, most libraries won't downgrade to http if you ask for https
|
||||
url = "http://" + url;
|
||||
}
|
||||
|
||||
let urlObject = URL.parse(url); // eslint-disable-line
|
||||
if (parsedArguments["upload-file"]) {
|
||||
// TODO: it's more complicated
|
||||
|
||||
4
test/fixtures/ansible/strange_http_method.yml
generated
vendored
4
test/fixtures/ansible/strange_http_method.yml
generated
vendored
@@ -1,6 +1,6 @@
|
||||
-
|
||||
name: 'localhost:28139'
|
||||
name: 'http://localhost:28139'
|
||||
uri:
|
||||
url: 'localhost:28139'
|
||||
url: 'http://localhost:28139'
|
||||
method: WHAT
|
||||
register: result
|
||||
|
||||
8
test/fixtures/cfml/delete_content_type.cfm
generated
vendored
8
test/fixtures/cfml/delete_content_type.cfm
generated
vendored
@@ -1,8 +0,0 @@
|
||||
httpService = new http();
|
||||
httpService.setUrl("localhost:28139");
|
||||
httpService.setMethod("POST");
|
||||
httpService.addParam(type="header", name="Content-Type", value="application/json");
|
||||
httpService.addParam(type="body", value="{}");
|
||||
|
||||
result = httpService.send().getPrefix();
|
||||
writeDump(result);
|
||||
2
test/fixtures/cfml/post_quotes_inside_data.cfm
generated
vendored
2
test/fixtures/cfml/post_quotes_inside_data.cfm
generated
vendored
@@ -1,5 +1,5 @@
|
||||
httpService = new http();
|
||||
httpService.setUrl("localhost:28139");
|
||||
httpService.setUrl("http://localhost:28139");
|
||||
httpService.setMethod("POST");
|
||||
httpService.addParam(type="header", name="Content-Type", value="application/x-www-form-urlencoded");
|
||||
httpService.addParam(type="body", value="field=don%27t%20you%20like%20quotes");
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
curl --data '{}' -H 'Content-Type: application/json' localhost:28139
|
||||
2
test/fixtures/dart/strange_http_method.dart
generated
vendored
2
test/fixtures/dart/strange_http_method.dart
generated
vendored
@@ -1,7 +1,7 @@
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
void main() async {
|
||||
var url = Uri.parse('localhost:28139');
|
||||
var url = Uri.parse('http://localhost:28139');
|
||||
var res = await http.what(url);
|
||||
if (res.statusCode != 200) throw Exception('http.what error: statusCode= ${res.statusCode}');
|
||||
print(res.body);
|
||||
|
||||
2
test/fixtures/go/strange_http_method.go
generated
vendored
2
test/fixtures/go/strange_http_method.go
generated
vendored
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
func main() {
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest("wHat", "localhost:28139", nil)
|
||||
req, err := http.NewRequest("wHat", "http://localhost:28139", nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
2
test/fixtures/java/get_silent.java
generated
vendored
2
test/fixtures/java/get_silent.java
generated
vendored
@@ -7,7 +7,7 @@ import java.util.Scanner;
|
||||
class Main {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
URL url = new URL("localhost:28139");
|
||||
URL url = new URL("http://localhost:28139");
|
||||
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
|
||||
httpConn.setRequestMethod("GET");
|
||||
|
||||
|
||||
2
test/fixtures/java/get_url_starting_with_http.java
generated
vendored
2
test/fixtures/java/get_url_starting_with_http.java
generated
vendored
@@ -7,7 +7,7 @@ import java.util.Scanner;
|
||||
class Main {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
URL url = new URL("httpbin.org/test");
|
||||
URL url = new URL("http://httpbin.org/test");
|
||||
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
|
||||
httpConn.setRequestMethod("GET");
|
||||
|
||||
|
||||
2
test/fixtures/java/get_with_header_without_value.java
generated
vendored
2
test/fixtures/java/get_with_header_without_value.java
generated
vendored
@@ -7,7 +7,7 @@ import java.util.Scanner;
|
||||
class Main {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
URL url = new URL("localhost:28139/get");
|
||||
URL url = new URL("http://localhost:28139/get");
|
||||
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
|
||||
httpConn.setRequestMethod("GET");
|
||||
|
||||
|
||||
2
test/fixtures/java/head_without_http.java
generated
vendored
2
test/fixtures/java/head_without_http.java
generated
vendored
@@ -7,7 +7,7 @@ import java.util.Scanner;
|
||||
class Main {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
URL url = new URL("localhost:28139/page");
|
||||
URL url = new URL("http://localhost:28139/page");
|
||||
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
|
||||
httpConn.setRequestMethod("HEAD");
|
||||
|
||||
|
||||
2
test/fixtures/java/post_quotes_inside_data.java
generated
vendored
2
test/fixtures/java/post_quotes_inside_data.java
generated
vendored
@@ -8,7 +8,7 @@ import java.util.Scanner;
|
||||
class Main {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
URL url = new URL("localhost:28139");
|
||||
URL url = new URL("http://localhost:28139");
|
||||
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
|
||||
httpConn.setRequestMethod("POST");
|
||||
|
||||
|
||||
2
test/fixtures/java/strange_http_method.java
generated
vendored
2
test/fixtures/java/strange_http_method.java
generated
vendored
@@ -7,7 +7,7 @@ import java.util.Scanner;
|
||||
class Main {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
URL url = new URL("localhost:28139");
|
||||
URL url = new URL("http://localhost:28139");
|
||||
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
|
||||
httpConn.setRequestMethod("wHat");
|
||||
|
||||
|
||||
7
test/fixtures/javascript/delete_content_type.js
generated
vendored
7
test/fixtures/javascript/delete_content_type.js
generated
vendored
@@ -1,7 +0,0 @@
|
||||
fetch('localhost:28139', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({})
|
||||
});
|
||||
2
test/fixtures/javascript/get_with_header_without_value.js
generated
vendored
2
test/fixtures/javascript/get_with_header_without_value.js
generated
vendored
@@ -1,4 +1,4 @@
|
||||
fetch('localhost:28139/get', {
|
||||
fetch('http://localhost:28139/get', {
|
||||
headers: {
|
||||
'Content-Type': 'text/xml;charset=UTF-8',
|
||||
'getWorkOrderCancel': ''
|
||||
|
||||
2
test/fixtures/javascript/post_quotes_inside_data.js
generated
vendored
2
test/fixtures/javascript/post_quotes_inside_data.js
generated
vendored
@@ -1,4 +1,4 @@
|
||||
fetch('localhost:28139', {
|
||||
fetch('http://localhost:28139', {
|
||||
method: 'POST',
|
||||
body: new URLSearchParams({
|
||||
'field': 'don\'t you like quotes'
|
||||
|
||||
2
test/fixtures/javascript/strange_http_method.js
generated
vendored
2
test/fixtures/javascript/strange_http_method.js
generated
vendored
@@ -1,3 +1,3 @@
|
||||
fetch('localhost:28139', {
|
||||
fetch('http://localhost:28139', {
|
||||
method: 'wHat'
|
||||
});
|
||||
|
||||
2
test/fixtures/matlab/strange_http_method.m
generated
vendored
2
test/fixtures/matlab/strange_http_method.m
generated
vendored
@@ -5,5 +5,5 @@
|
||||
import matlab.net.*
|
||||
import matlab.net.http.*
|
||||
|
||||
uri = URI('localhost:28139');
|
||||
uri = URI('http://localhost:28139');
|
||||
response = RequestMessage('what').send(uri.EncodedURI);
|
||||
|
||||
11
test/fixtures/node-axios/delete_content_type.js
generated
vendored
11
test/fixtures/node-axios/delete_content_type.js
generated
vendored
@@ -1,11 +0,0 @@
|
||||
const axios = require('axios');
|
||||
|
||||
const response = await axios.post(
|
||||
'localhost:28139',
|
||||
{},
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
}
|
||||
);
|
||||
2
test/fixtures/node-axios/get_url_starting_with_http.js
generated
vendored
2
test/fixtures/node-axios/get_url_starting_with_http.js
generated
vendored
@@ -1,3 +1,3 @@
|
||||
const axios = require('axios');
|
||||
|
||||
const response = await axios.get('httpbin.org/test');
|
||||
const response = await axios.get('http://httpbin.org/test');
|
||||
|
||||
2
test/fixtures/node-axios/get_with_header_without_value.js
generated
vendored
2
test/fixtures/node-axios/get_with_header_without_value.js
generated
vendored
@@ -1,6 +1,6 @@
|
||||
const axios = require('axios');
|
||||
|
||||
const response = await axios.get('localhost:28139/get', {
|
||||
const response = await axios.get('http://localhost:28139/get', {
|
||||
headers: {
|
||||
'Content-Type': 'text/xml;charset=UTF-8',
|
||||
'getWorkOrderCancel': ''
|
||||
|
||||
2
test/fixtures/node-axios/head_without_http.js
generated
vendored
2
test/fixtures/node-axios/head_without_http.js
generated
vendored
@@ -1,3 +1,3 @@
|
||||
const axios = require('axios');
|
||||
|
||||
const response = await axios.head('localhost:28139/page');
|
||||
const response = await axios.head('http://localhost:28139/page');
|
||||
|
||||
2
test/fixtures/node-axios/post_quotes_inside_data.js
generated
vendored
2
test/fixtures/node-axios/post_quotes_inside_data.js
generated
vendored
@@ -1,7 +1,7 @@
|
||||
const axios = require('axios');
|
||||
|
||||
const response = await axios.post(
|
||||
'localhost:28139',
|
||||
'http://localhost:28139',
|
||||
new URLSearchParams({
|
||||
'field': 'don\'t you like quotes'
|
||||
})
|
||||
|
||||
2
test/fixtures/node-axios/strange_http_method.js
generated
vendored
2
test/fixtures/node-axios/strange_http_method.js
generated
vendored
@@ -1,3 +1,3 @@
|
||||
const axios = require('axios');
|
||||
|
||||
const response = await axios('localhost:28139');
|
||||
const response = await axios('http://localhost:28139');
|
||||
|
||||
2
test/fixtures/node-request/strange_http_method.js
generated
vendored
2
test/fixtures/node-request/strange_http_method.js
generated
vendored
@@ -1,7 +1,7 @@
|
||||
var request = require('request');
|
||||
|
||||
var options = {
|
||||
url: 'localhost:28139',
|
||||
url: 'http://localhost:28139',
|
||||
method: 'WHAT'
|
||||
};
|
||||
|
||||
|
||||
2
test/fixtures/node/get_with_header_without_value.js
generated
vendored
2
test/fixtures/node/get_with_header_without_value.js
generated
vendored
@@ -1,6 +1,6 @@
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
fetch('localhost:28139/get', {
|
||||
fetch('http://localhost:28139/get', {
|
||||
headers: {
|
||||
'Content-Type': 'text/xml;charset=UTF-8',
|
||||
'getWorkOrderCancel': ''
|
||||
|
||||
2
test/fixtures/node/post_quotes_inside_data.js
generated
vendored
2
test/fixtures/node/post_quotes_inside_data.js
generated
vendored
@@ -1,6 +1,6 @@
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
fetch('localhost:28139', {
|
||||
fetch('http://localhost:28139', {
|
||||
method: 'POST',
|
||||
body: new URLSearchParams({
|
||||
'field': 'don\'t you like quotes'
|
||||
|
||||
2
test/fixtures/node/strange_http_method.js
generated
vendored
2
test/fixtures/node/strange_http_method.js
generated
vendored
@@ -1,5 +1,5 @@
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
fetch('localhost:28139', {
|
||||
fetch('http://localhost:28139', {
|
||||
method: 'wHat'
|
||||
});
|
||||
|
||||
4
test/fixtures/parser/strange_http_method.json
generated
vendored
4
test/fixtures/parser/strange_http_method.json
generated
vendored
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"url": "localhost:28139",
|
||||
"url": "http://localhost:28139",
|
||||
"method": "wHat",
|
||||
"urlWithoutQuery": "localhost:28139"
|
||||
"urlWithoutQuery": "http://localhost:28139"
|
||||
}
|
||||
|
||||
13
test/fixtures/php/delete_content_type.php
generated
vendored
13
test/fixtures/php/delete_content_type.php
generated
vendored
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, 'localhost:28139');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Content-Type' => 'application/json',
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, '{}');
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
2
test/fixtures/php/post_quotes_inside_data.php
generated
vendored
2
test/fixtures/php/post_quotes_inside_data.php
generated
vendored
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, 'localhost:28139');
|
||||
curl_setopt($ch, CURLOPT_URL, 'http://localhost:28139');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
|
||||
2
test/fixtures/php/strange_http_method.php
generated
vendored
2
test/fixtures/php/strange_http_method.php
generated
vendored
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, 'localhost:28139');
|
||||
curl_setopt($ch, CURLOPT_URL, 'http://localhost:28139');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'wHat');
|
||||
|
||||
|
||||
10
test/fixtures/python/delete_content_type.py
generated
vendored
10
test/fixtures/python/delete_content_type.py
generated
vendored
@@ -1,10 +0,0 @@
|
||||
import requests
|
||||
|
||||
headers = {
|
||||
# Already added when you pass json=
|
||||
# 'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
json_data = {}
|
||||
|
||||
response = requests.post('http://localhost:28139', headers=headers, json=json_data)
|
||||
2
test/fixtures/rust/strange_http_method.rs
generated
vendored
2
test/fixtures/rust/strange_http_method.rs
generated
vendored
@@ -2,7 +2,7 @@ extern crate reqwest;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let res = reqwest::Client::new()
|
||||
.what("localhost:28139")
|
||||
.what("http://localhost:28139")
|
||||
.send()?
|
||||
.text()?;
|
||||
println!("{}", res);
|
||||
|
||||
Reference in New Issue
Block a user