parse Cookie header and --cookie losslessly (#347)

This commit is contained in:
Boris Verkhovskiy
2022-03-18 16:23:44 -07:00
committed by GitHub
parent 081c4a8934
commit b12081bc7e
49 changed files with 214 additions and 162 deletions

View File

@@ -9,6 +9,6 @@
User-Agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
Referer: 'http://www.wikipedia.org/'
Connection: 'keep-alive'
Cookie: 'GeoIP=US:Albuquerque:35.1241:-106.7675:v4; uls-previous-languages=%5B%22en%22%5D; mediaWiki.user.sessionId=VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y; centralnotice_buckets_by_campaign=%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D; centralnotice_bannercount_fr12=22; centralnotice_bannercount_fr12-wait=14'
Connection: 'keep-alive'
register: result

View File

@@ -7,8 +7,8 @@ void main() async {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Referer': 'http://www.wikipedia.org/',
'Connection': 'keep-alive',
'Cookie': 'GeoIP=US:Albuquerque:35.1241:-106.7675:v4; uls-previous-languages=%5B%22en%22%5D; mediaWiki.user.sessionId=VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y; centralnotice_buckets_by_campaign=%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D; centralnotice_bannercount_fr12=22; centralnotice_bannercount_fr12-wait=14',
'Connection': 'keep-alive',
'Accept-Encoding': 'gzip',
};

View File

@@ -8,9 +8,9 @@ void main() async {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
'Accept': '*/*',
'Referer': 'http://www.w3schools.com/ajax/tryit_view.asp?x=0.07944501144811511',
'Cookie': '_gat=1; ASPSESSIONIDACCRDTDC=MCMDKFMBLLLHGKCGNMKNGPKI; _ga=GA1.2.1424920226.1419478126',
'Connection': 'keep-alive',
'Content-Length': '0',
'Cookie': '_gat=1; ASPSESSIONIDACCRDTDC=MCMDKFMBLLLHGKCGNMKNGPKI; _ga=GA1.2.1424920226.1419478126',
'Accept-Encoding': 'gzip',
};

View File

@@ -4,7 +4,7 @@ request = %HTTPoison.Request{
options: [],
headers: [
{~s|x-msisdn|, ~s|XXXXXXXXXXXXX|},
{~s|User-Agent|, ~s|Mozilla Android6.1|},
{~s|user-agent|, ~s|Mozilla Android6.1|},
],
params: [
{~s|p|, ~s|5|},

View File

@@ -18,8 +18,8 @@ func main() {
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36")
req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
req.Header.Set("Referer", "http://www.wikipedia.org/")
req.Header.Set("Connection", "keep-alive")
req.Header.Set("Cookie", "GeoIP=US:Albuquerque:35.1241:-106.7675:v4; uls-previous-languages=%5B%22en%22%5D; mediaWiki.user.sessionId=VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y; centralnotice_buckets_by_campaign=%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D; centralnotice_bannercount_fr12=22; centralnotice_bannercount_fr12-wait=14")
req.Header.Set("Connection", "keep-alive")
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)

View File

@@ -12,7 +12,6 @@ class Main {
httpConn.setRequestMethod("GET");
httpConn.setRequestProperty("accept", "application/json");
httpConn.setRequestProperty("Cookie", "mysamplecookie=someValue; emptycookie=; otherCookie=2");
InputStream responseStream = httpConn.getResponseCode() / 100 == 2

View File

@@ -12,7 +12,7 @@ class Main {
httpConn.setRequestMethod("GET");
httpConn.setRequestProperty("x-msisdn", "XXXXXXXXXXXXX");
httpConn.setRequestProperty("User-Agent", "Mozilla Android6.1");
httpConn.setRequestProperty("user-agent", "Mozilla Android6.1");
InputStream responseStream = httpConn.getResponseCode() / 100 == 2
? httpConn.getInputStream()

View File

@@ -12,7 +12,7 @@ class Main {
httpConn.setRequestMethod("GET");
httpConn.setRequestProperty("x-msisdn", "XXXXXXXXXXXXX");
httpConn.setRequestProperty("User-Agent", "Mozilla Android6.1");
httpConn.setRequestProperty("user-agent", "Mozilla Android6.1");
InputStream responseStream = httpConn.getResponseCode() / 100 == 2
? httpConn.getInputStream()

View File

@@ -16,9 +16,8 @@ class Main {
httpConn.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36");
httpConn.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
httpConn.setRequestProperty("Referer", "http://www.wikipedia.org/");
httpConn.setRequestProperty("Connection", "keep-alive");
httpConn.setRequestProperty("Cookie", "GeoIP=US:Albuquerque:35.1241:-106.7675:v4; uls-previous-languages=%5B%22en%22%5D; mediaWiki.user.sessionId=VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y; centralnotice_buckets_by_campaign=%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D; centralnotice_bannercount_fr12=22; centralnotice_bannercount_fr12-wait=14");
httpConn.setRequestProperty("Connection", "keep-alive");
InputStream responseStream = httpConn.getResponseCode() / 100 == 2
? httpConn.getInputStream()

View File

@@ -17,12 +17,11 @@ class Main {
httpConn.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36");
httpConn.setRequestProperty("accept", "application/json");
httpConn.setRequestProperty("Referer", "https://httpbin.org/");
httpConn.setRequestProperty("Cookie", "authCookie=123");
httpConn.setRequestProperty("Connection", "keep-alive");
httpConn.setRequestProperty("Cache-Control", "no-cache");
httpConn.setRequestProperty("Sec-Metadata", "destination=empty, site=same-origin");
httpConn.setRequestProperty("Cookie", "authCookie=123");
InputStream responseStream = httpConn.getResponseCode() / 100 == 2
? httpConn.getInputStream()
: httpConn.getErrorStream();

View File

@@ -11,8 +11,7 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("GET");
httpConn.setRequestProperty("Cookie", "secure_user_id=InNlY3VyZTEwNjI3Ig%3D%3D--3b5df49345735791f2b80eddafb630cdcba76a1d; adaptive_image=1440; has_js=1; ccShowCookieIcon=no; _web_session=Y2h...e5");
httpConn.setRequestProperty("cookie", "secure_user_id=InNlY3VyZTEwNjI3Ig%3D%3D--3b5df49345735791f2b80eddafb630cdcba76a1d; adaptive_image=1440; has_js=1; ccShowCookieIcon=no; _web_session=Y2h...e5");
InputStream responseStream = httpConn.getResponseCode() / 100 == 2
? httpConn.getInputStream()

View File

@@ -12,6 +12,7 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Cookie", "X-BackEndCookie=S-1-5-21-1234556-56678-12345-2345=alphanumericstring12345/anotheralphanumericstring12345/scsiAdf/P; ClientId=LoremIupsum; PrivateComputer=true; PBack=0; cadata=bx88rrCBehITlBWSozO2l2hlFGu//JjT1/k6dewX5shV32jANUZSMU6GR+M25B6YpBODEgXzxfIHDnvxNC6SJoaE/d8RWX3uDnbkd+m91jNhMXNSYIRYTJHVFdPG06AE; cadataTTL=NfDhBViTJMUdC+ir+6BYvg==; cadataKey=qUY+OLTD9V14CFK6/CUPyrJWMxl1FFqZFjB8/qcS0/q55eqGvP9bWvX+XuSYVv3hIGAn9QNPhIDK6NP9LwCBdu25f2BUFDUWJruGO8MW02izSWzRUnni00xWQq3Y3nNKvpvO+OIR641BPHVZ0+lzCw2Wt8uzEnryCWAjlleozF/XWjpTN4/AaTmcIjEZUDN+fo4494rD0mADtEHv2gmd5mhLe+iyii/L9nAB3UuiJomwbRbKgy22Tj8cyavmLC4ZaViqW9E102NOLU4FYLgdZVET+mbdg==; cadataIV=bTM88YL1zmz7FsBEB0y3nI2SrdSTy+KLxCpx2FRfIZYFo2spN1IHQMSCT76OXrg79sVPhyqXk+N9rOj6M9KsQl4KqMNVBcoXgp24POpgoTwd4FBmKtAYbd9SDErna3jrMO168ML9PDG18K3CnBf6YG1tsIs0gXOEP9LzHVmUPF7KCKqUFiOiZGWuwmPhl85eo77BbEpVN2JkPnzuQWn6tC0cY4f2cJDlr3Z23SrAUVwwXmgRg2DXfOF5MIEkpwYiiI6sABCD9rsSnE6zTXlvZg33hjiD/ywUV1ZWjI2M/4zBixa4s150+dOnMmvtEFs/nOMnvMJui4PEDlTA==; cadataSig=WL3hB+av7sO3bzjL+Efe5b4exnvQxSInH3U5jDvfnPcttSp0XUF3y/NB573C0CTBYuOH/40smFssXlrKhT9tG2ITivdSIIamOmarmC8XwFOv9qQIFMHofcO/jjRDMqF0qRk7WBAC2FgBQrf2Tvq7wk5IX/JHn6zhlgKALAAqH9L9JNC244etnjj9YNaMDYEHV2M2jVTu3FsELqw1rSSqp0hEBlh+aFBvYCBg5hS1mVI76ZCHZVa0OUejiH2yiZyJIKHUI+Sv0rpU3iiQNtIFmGEdwhoo/rga4s4Dc2UsJLQ8c0yGlZgflYs+7Q5gPr74/mTUin60ej/w3M0roUl3FQ==; UC=d8be544621964f3c9865b3ee872fd432; AppcacheVer=15.0.1236.3:en-usbase; X-OWA-CANARY=VOXQP6xtGkiNnv7E4rFt8TrmclqVFtQI4IJqZflrR7Wz9AMPkMsFoyAlquw1YGsTUxIkVouAcvk.");
httpConn.setRequestProperty("Origin", "https://nih.mail.edu.fr");
httpConn.setRequestProperty("Accept-Encoding", "gzip, deflate, br");
httpConn.setRequestProperty("X-EWS-TargetVersion", "2.5");
@@ -33,8 +34,6 @@ class Main {
httpConn.setRequestProperty("X-OWA-ClientBegin", "2016-11-27T07:17:02.513");
httpConn.setRequestProperty("X-OWA-Attempt", "1");
httpConn.setRequestProperty("Cookie", "X-BackEndCookie=S-1-5-21-1234556-56678-12345-2345=alphanumericstring12345/anotheralphanumericstring12345/scsiAdf/P; ClientId=LoremIupsum; PrivateComputer=true; PBack=0; cadata=bx88rrCBehITlBWSozO2l2hlFGu//JjT1/k6dewX5shV32jANUZSMU6GR+M25B6YpBODEgXzxfIHDnvxNC6SJoaE/d8RWX3uDnbkd+m91jNhMXNSYIRYTJHVFdPG06AE; cadataTTL=NfDhBViTJMUdC+ir+6BYvg==; cadataKey=qUY+OLTD9V14CFK6/CUPyrJWMxl1FFqZFjB8/qcS0/q55eqGvP9bWvX+XuSYVv3hIGAn9QNPhIDK6NP9LwCBdu25f2BUFDUWJruGO8MW02izSWzRUnni00xWQq3Y3nNKvpvO+OIR641BPHVZ0+lzCw2Wt8uzEnryCWAjlleozF/XWjpTN4/AaTmcIjEZUDN+fo4494rD0mADtEHv2gmd5mhLe+iyii/L9nAB3UuiJomwbRbKgy22Tj8cyavmLC4ZaViqW9E102NOLU4FYLgdZVET+mbdg==; cadataIV=bTM88YL1zmz7FsBEB0y3nI2SrdSTy+KLxCpx2FRfIZYFo2spN1IHQMSCT76OXrg79sVPhyqXk+N9rOj6M9KsQl4KqMNVBcoXgp24POpgoTwd4FBmKtAYbd9SDErna3jrMO168ML9PDG18K3CnBf6YG1tsIs0gXOEP9LzHVmUPF7KCKqUFiOiZGWuwmPhl85eo77BbEpVN2JkPnzuQWn6tC0cY4f2cJDlr3Z23SrAUVwwXmgRg2DXfOF5MIEkpwYiiI6sABCD9rsSnE6zTXlvZg33hjiD/ywUV1ZWjI2M/4zBixa4s150+dOnMmvtEFs/nOMnvMJui4PEDlTA==; cadataSig=WL3hB+av7sO3bzjL+Efe5b4exnvQxSInH3U5jDvfnPcttSp0XUF3y/NB573C0CTBYuOH/40smFssXlrKhT9tG2ITivdSIIamOmarmC8XwFOv9qQIFMHofcO/jjRDMqF0qRk7WBAC2FgBQrf2Tvq7wk5IX/JHn6zhlgKALAAqH9L9JNC244etnjj9YNaMDYEHV2M2jVTu3FsELqw1rSSqp0hEBlh+aFBvYCBg5hS1mVI76ZCHZVa0OUejiH2yiZyJIKHUI+Sv0rpU3iiQNtIFmGEdwhoo/rga4s4Dc2UsJLQ8c0yGlZgflYs+7Q5gPr74/mTUin60ej/w3M0roUl3FQ==; UC=d8be544621964f3c9865b3ee872fd432; AppcacheVer=15.0.1236.3:en-usbase; X-OWA-CANARY=VOXQP6xtGkiNnv7E4rFt8TrmclqVFtQI4IJqZflrR7Wz9AMPkMsFoyAlquw1YGsTUxIkVouAcvk.");
httpConn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
writer.write("{\"__type\":\"CreateItemJsonRequest:#Exchange\",\"Header\":{\"__type\":\"JsonRequestHeaders:#Exchange\",\"RequestServerVersion\":\"Exchange2013\",\"TimeZoneContext\":{\"__type\":\"TimeZoneContext:#Exchange\",\"TimeZoneDefinition\":{\"__type\":\"TimeZoneDefinitionType:#Exchange\",\"Id\":\"France Standard Time\"}}},\"Body\":{\"__type\":\"CreateItemRequest:#Exchange\",\"Items\":[{\"__type\":\"Message:#Exchange\",\"Subject\":\"API\",\"Body\":{\"__type\":\"BodyContentType:#Exchange\",\"BodyType\":\"HTML\",\"Value\":\"<html><head><meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html; charset=UTF-8\\\"><style type=\\\"text/css\\\" style=\\\"display:none\\\"><!-- p { margin-top: 0px; margin-bottom: 0px; }--></style></head><body dir=\\\"ltr\\\" style=\\\"font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;\\\"><p>API Test for NickC<br></p></body></html>\"},\"Importance\":\"Normal\",\"From\":null,\"ToRecipients\":[{\"Name\":\"George LUCAS\",\"EmailAddress\":\"George.LUCAS@nih.mail.edu.fr\",\"RoutingType\":\"SMTP\",\"MailboxType\":\"Mailbox\",\"OriginalDisplayName\":\"George.LUCAS@nih.mail.edu.fr\",\"SipUri\":\" \"}],\"CcRecipients\":[],\"BccRecipients\":[],\"Sensitivity\":\"Normal\",\"IsDeliveryReceiptRequested\":false,\"IsReadReceiptRequested\":false}],\"ClientSupportsIrm\":true,\"OutboundCharset\":\"AutoDetect\",\"MessageDisposition\":\"SendAndSaveCopy\",\"ComposeOperation\":\"newMail\"}}");

View File

@@ -17,11 +17,10 @@ class Main {
httpConn.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36");
httpConn.setRequestProperty("Accept", "*/*");
httpConn.setRequestProperty("Referer", "http://www.w3schools.com/ajax/tryit_view.asp?x=0.07944501144811511");
httpConn.setRequestProperty("Cookie", "_gat=1; ASPSESSIONIDACCRDTDC=MCMDKFMBLLLHGKCGNMKNGPKI; _ga=GA1.2.1424920226.1419478126");
httpConn.setRequestProperty("Connection", "keep-alive");
httpConn.setRequestProperty("Content-Length", "0");
httpConn.setRequestProperty("Cookie", "_gat=1; ASPSESSIONIDACCRDTDC=MCMDKFMBLLLHGKCGNMKNGPKI; _ga=GA1.2.1424920226.1419478126");
InputStream responseStream = httpConn.getResponseCode() / 100 == 2
? httpConn.getInputStream()
: httpConn.getErrorStream();

View File

@@ -15,7 +15,6 @@ class Main {
httpConn.setRequestProperty("A", "''a'");
httpConn.setRequestProperty("B", "\"");
httpConn.setRequestProperty("Cookie", "x=1'; y=2\"");
byte[] message = ("ol':asd\"").getBytes("UTF-8");

View File

@@ -5,7 +5,7 @@ fetch('http://en.wikipedia.org/', {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Referer': 'http://www.wikipedia.org/',
'Connection': 'keep-alive',
'Cookie': 'GeoIP=US:Albuquerque:35.1241:-106.7675:v4; uls-previous-languages=%5B%22en%22%5D; mediaWiki.user.sessionId=VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y; centralnotice_buckets_by_campaign=%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D; centralnotice_bannercount_fr12=22; centralnotice_bannercount_fr12-wait=14'
'Cookie': 'GeoIP=US:Albuquerque:35.1241:-106.7675:v4; uls-previous-languages=%5B%22en%22%5D; mediaWiki.user.sessionId=VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y; centralnotice_buckets_by_campaign=%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D; centralnotice_bannercount_fr12=22; centralnotice_bannercount_fr12-wait=14',
'Connection': 'keep-alive'
}
});

View File

@@ -7,8 +7,8 @@ fetch('http://www.w3schools.com/ajax/demo_post.asp', {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
'Accept': '*/*',
'Referer': 'http://www.w3schools.com/ajax/tryit_view.asp?x=0.07944501144811511',
'Cookie': '_gat=1; ASPSESSIONIDACCRDTDC=MCMDKFMBLLLHGKCGNMKNGPKI; _ga=GA1.2.1424920226.1419478126',
'Connection': 'keep-alive',
'Content-Length': '0',
'Cookie': '_gat=1; ASPSESSIONIDACCRDTDC=MCMDKFMBLLLHGKCGNMKNGPKI; _ga=GA1.2.1424920226.1419478126'
'Content-Length': '0'
}
});

View File

@@ -23,7 +23,7 @@ params = {
};
header = [
HeaderField('x-msisdn', 'XXXXXXXXXXXXX')
HeaderField('User-Agent', 'Mozilla Android6.1')
HeaderField('user-agent', 'Mozilla Android6.1')
]';
uri = URI('http://205.147.98.6/vc/moviesmagic', QueryParameter(params'));
response = RequestMessage('get', header).send(uri.EncodedURI);

View File

@@ -15,8 +15,8 @@ options = weboptions(...
'Accept-Language' 'en-US,en;q=0.8'
'Accept' 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
'Referer' 'http://www.wikipedia.org/'
'Connection' 'keep-alive'
'Cookie' char(join(join(cookies, '='), '; '))
'Connection' 'keep-alive'
}...
);
response = webread(uri, options);

View File

@@ -25,6 +25,7 @@ options = weboptions(...
'UserAgent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36',...
'MediaType', 'application/json; charset=UTF-8',...
'HeaderFields', {
'Cookie' char(join(join(cookies, '='), '; '))
'Origin' 'https://nih.mail.edu.fr'
'Accept-Encoding' 'gzip, deflate, br'
'X-EWS-TargetVersion' '2.5'
@@ -43,7 +44,6 @@ options = weboptions(...
'DNT' '1'
'X-OWA-ClientBegin' '2016-11-27T07:17:02.513'
'X-OWA-Attempt' '1'
'Cookie' char(join(join(cookies, '='), '; '))
}...
);
response = webwrite(uri, body, options);

View File

@@ -6,8 +6,8 @@ var headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Referer': 'http://www.wikipedia.org/',
'Connection': 'keep-alive',
'Cookie': 'GeoIP=US:Albuquerque:35.1241:-106.7675:v4; uls-previous-languages=%5B%22en%22%5D; mediaWiki.user.sessionId=VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y; centralnotice_buckets_by_campaign=%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D; centralnotice_bannercount_fr12=22; centralnotice_bannercount_fr12-wait=14'
'Cookie': 'GeoIP=US:Albuquerque:35.1241:-106.7675:v4; uls-previous-languages=%5B%22en%22%5D; mediaWiki.user.sessionId=VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y; centralnotice_buckets_by_campaign=%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D; centralnotice_bannercount_fr12=22; centralnotice_bannercount_fr12-wait=14',
'Connection': 'keep-alive'
};
var options = {

View File

@@ -7,9 +7,9 @@ var headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
'Accept': '*/*',
'Referer': 'http://www.w3schools.com/ajax/tryit_view.asp?x=0.07944501144811511',
'Cookie': '_gat=1; ASPSESSIONIDACCRDTDC=MCMDKFMBLLLHGKCGNMKNGPKI; _ga=GA1.2.1424920226.1419478126',
'Connection': 'keep-alive',
'Content-Length': '0',
'Cookie': '_gat=1; ASPSESSIONIDACCRDTDC=MCMDKFMBLLLHGKCGNMKNGPKI; _ga=GA1.2.1424920226.1419478126'
'Content-Length': '0'
};
var options = {

View File

@@ -1,6 +1,32 @@
{
"url": "http://en.wikipedia.org/",
"urlWithoutQuery": "http://en.wikipedia.org/",
"cookies": [
[
"GeoIP",
"US:Albuquerque:35.1241:-106.7675:v4"
],
[
"uls-previous-languages",
"%5B%22en%22%5D"
],
[
"mediaWiki.user.sessionId",
"VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y"
],
[
"centralnotice_buckets_by_campaign",
"%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D"
],
[
"centralnotice_bannercount_fr12",
"22"
],
[
"centralnotice_bannercount_fr12-wait",
"14"
]
],
"compressed": true,
"headers": [
[
@@ -23,19 +49,14 @@
"Referer",
"http://www.wikipedia.org/"
],
[
"Cookie",
"GeoIP=US:Albuquerque:35.1241:-106.7675:v4; uls-previous-languages=%5B%22en%22%5D; mediaWiki.user.sessionId=VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y; centralnotice_buckets_by_campaign=%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D; centralnotice_bannercount_fr12=22; centralnotice_bannercount_fr12-wait=14"
],
[
"Connection",
"keep-alive"
]
],
"method": "get",
"cookies": {
"GeoIP": "US:Albuquerque:35.1241:-106.7675:v4",
"uls-previous-languages": "%5B%22en%22%5D",
"mediaWiki.user.sessionId": "VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y",
"centralnotice_buckets_by_campaign": "%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D",
"centralnotice_bannercount_fr12": "22",
"centralnotice_bannercount_fr12-wait": "14"
},
"cookieString": "GeoIP=US:Albuquerque:35.1241:-106.7675:v4; uls-previous-languages=%5B%22en%22%5D; mediaWiki.user.sessionId=VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y; centralnotice_buckets_by_campaign=%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D; centralnotice_bannercount_fr12=22; centralnotice_bannercount_fr12-wait=14"
"method": "get"
}

View File

@@ -1,6 +1,20 @@
{
"url": "http://www.w3schools.com/ajax/demo_post.asp",
"urlWithoutQuery": "http://www.w3schools.com/ajax/demo_post.asp",
"cookies": [
[
"_gat",
"1"
],
[
"ASPSESSIONIDACCRDTDC",
"MCMDKFMBLLLHGKCGNMKNGPKI"
],
[
"_ga",
"GA1.2.1424920226.1419478126"
]
],
"compressed": true,
"headers": [
[
@@ -27,6 +41,10 @@
"Referer",
"http://www.w3schools.com/ajax/tryit_view.asp?x=0.07944501144811511"
],
[
"Cookie",
"_gat=1; ASPSESSIONIDACCRDTDC=MCMDKFMBLLLHGKCGNMKNGPKI; _ga=GA1.2.1424920226.1419478126"
],
[
"Connection",
"keep-alive"
@@ -36,11 +54,5 @@
"0"
]
],
"method": "post",
"cookies": {
"_gat": "1",
"ASPSESSIONIDACCRDTDC": "MCMDKFMBLLLHGKCGNMKNGPKI",
"_ga": "GA1.2.1424920226.1419478126"
},
"cookieString": "_gat=1; ASPSESSIONIDACCRDTDC=MCMDKFMBLLLHGKCGNMKNGPKI; _ga=GA1.2.1424920226.1419478126"
"method": "post"
}

View File

@@ -2,7 +2,7 @@ import requests
headers = {
'x-msisdn': 'XXXXXXXXXXXXX',
'User-Agent': 'Mozilla Android6.1',
'user-agent': 'Mozilla Android6.1',
}
params = {

View File

@@ -2,7 +2,7 @@ import requests
headers = {
'x-msisdn': 'XXXXXXXXXXXXX',
'User-Agent': 'Mozilla Android6.1',
'user-agent': 'Mozilla Android6.1',
}
params = {

View File

@@ -15,6 +15,8 @@ headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Referer': 'http://www.wikipedia.org/',
# Requests sorts cookies= alphabetically
# 'Cookie': 'GeoIP=US:Albuquerque:35.1241:-106.7675:v4; uls-previous-languages=%5B%22en%22%5D; mediaWiki.user.sessionId=VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y; centralnotice_buckets_by_campaign=%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D; centralnotice_bannercount_fr12=22; centralnotice_bannercount_fr12-wait=14',
'Connection': 'keep-alive',
}

View File

@@ -9,6 +9,8 @@ cookies = {
}
headers = {
# Requests sorts cookies= alphabetically
# 'cookie': 'secure_user_id=InNlY3VyZTEwNjI3Ig%3D%3D--3b5df49345735791f2b80eddafb630cdcba76a1d; adaptive_image=1440; has_js=1; ccShowCookieIcon=no; _web_session=Y2h...e5',
}
response = requests.get('http://www.url.com/page', headers=headers, cookies=cookies)

View File

@@ -16,6 +16,8 @@ cookies = {
}
headers = {
# Requests sorts cookies= alphabetically
# 'Cookie': 'X-BackEndCookie=S-1-5-21-1234556-56678-12345-2345=alphanumericstring12345/anotheralphanumericstring12345/scsiAdf/P; ClientId=LoremIupsum; PrivateComputer=true; PBack=0; cadata=bx88rrCBehITlBWSozO2l2hlFGu//JjT1/k6dewX5shV32jANUZSMU6GR+M25B6YpBODEgXzxfIHDnvxNC6SJoaE/d8RWX3uDnbkd+m91jNhMXNSYIRYTJHVFdPG06AE; cadataTTL=NfDhBViTJMUdC+ir+6BYvg==; cadataKey=qUY+OLTD9V14CFK6/CUPyrJWMxl1FFqZFjB8/qcS0/q55eqGvP9bWvX+XuSYVv3hIGAn9QNPhIDK6NP9LwCBdu25f2BUFDUWJruGO8MW02izSWzRUnni00xWQq3Y3nNKvpvO+OIR641BPHVZ0+lzCw2Wt8uzEnryCWAjlleozF/XWjpTN4/AaTmcIjEZUDN+fo4494rD0mADtEHv2gmd5mhLe+iyii/L9nAB3UuiJomwbRbKgy22Tj8cyavmLC4ZaViqW9E102NOLU4FYLgdZVET+mbdg==; cadataIV=bTM88YL1zmz7FsBEB0y3nI2SrdSTy+KLxCpx2FRfIZYFo2spN1IHQMSCT76OXrg79sVPhyqXk+N9rOj6M9KsQl4KqMNVBcoXgp24POpgoTwd4FBmKtAYbd9SDErna3jrMO168ML9PDG18K3CnBf6YG1tsIs0gXOEP9LzHVmUPF7KCKqUFiOiZGWuwmPhl85eo77BbEpVN2JkPnzuQWn6tC0cY4f2cJDlr3Z23SrAUVwwXmgRg2DXfOF5MIEkpwYiiI6sABCD9rsSnE6zTXlvZg33hjiD/ywUV1ZWjI2M/4zBixa4s150+dOnMmvtEFs/nOMnvMJui4PEDlTA==; cadataSig=WL3hB+av7sO3bzjL+Efe5b4exnvQxSInH3U5jDvfnPcttSp0XUF3y/NB573C0CTBYuOH/40smFssXlrKhT9tG2ITivdSIIamOmarmC8XwFOv9qQIFMHofcO/jjRDMqF0qRk7WBAC2FgBQrf2Tvq7wk5IX/JHn6zhlgKALAAqH9L9JNC244etnjj9YNaMDYEHV2M2jVTu3FsELqw1rSSqp0hEBlh+aFBvYCBg5hS1mVI76ZCHZVa0OUejiH2yiZyJIKHUI+Sv0rpU3iiQNtIFmGEdwhoo/rga4s4Dc2UsJLQ8c0yGlZgflYs+7Q5gPr74/mTUin60ej/w3M0roUl3FQ==; UC=d8be544621964f3c9865b3ee872fd432; AppcacheVer=15.0.1236.3:en-usbase; X-OWA-CANARY=VOXQP6xtGkiNnv7E4rFt8TrmclqVFtQI4IJqZflrR7Wz9AMPkMsFoyAlquw1YGsTUxIkVouAcvk.',
'Origin': 'https://nih.mail.edu.fr',
'Accept-Encoding': 'gzip, deflate, br',
'X-EWS-TargetVersion': '2.5',

View File

@@ -13,6 +13,8 @@ headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
'Accept': '*/*',
'Referer': 'http://www.w3schools.com/ajax/tryit_view.asp?x=0.07944501144811511',
# Requests sorts cookies= alphabetically
# 'Cookie': '_gat=1; ASPSESSIONIDACCRDTDC=MCMDKFMBLLLHGKCGNMKNGPKI; _ga=GA1.2.1424920226.1419478126',
'Connection': 'keep-alive',
'Content-Length': '0',
}

View File

@@ -2,7 +2,7 @@ require(httr)
headers = c(
`x-msisdn` = 'XXXXXXXXXXXXX',
`User-Agent` = 'Mozilla Android6.1'
`user-agent` = 'Mozilla Android6.1'
)
params = list(

View File

@@ -4,7 +4,7 @@ use reqwest::header;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut headers = header::HeaderMap::new();
headers.insert("x-msisdn", "XXXXXXXXXXXXX".parse().unwrap());
headers.insert("User-Agent", "Mozilla Android6.1".parse().unwrap());
headers.insert("user-agent", "Mozilla Android6.1".parse().unwrap());
let res = reqwest::Client::new()
.get("http://205.147.98.6/vc/moviesmagic?p=5&pub=testmovie&tkn=817263812")

View File

@@ -23,6 +23,9 @@ requests:
-
name: Referer
value: 'https://httpbin.org/'
-
name: Cookie
value: authCookie=123
-
name: Connection
value: keep-alive
@@ -32,6 +35,3 @@ requests:
-
name: Sec-Metadata
value: 'destination=empty, site=same-origin'
-
name: Cookie
value: authCookie=123

View File

@@ -30,18 +30,13 @@ export const _toDart = r => {
'\n'
}
const hasHeaders = r.headers || r.cookies || r.compressed || r.isDataBinary || r.method === 'put'
const hasHeaders = r.headers || r.compressed || r.isDataBinary || r.method === 'put'
if (hasHeaders) {
s += ' var headers = {\n'
for (const [hname, hval] of (r.headers || [])) {
s += " '" + hname + "': '" + hval + "',\n"
}
if (r.cookies) {
const cookiestr = util.serializeCookies(r.cookies)
s += " 'Cookie': '" + cookiestr + "',\n"
}
if (r.auth) s += " 'Authorization': authn,\n"
if (r.compressed) s += " 'Accept-Encoding': 'gzip',\n"
if (!util.hasHeader(r, 'content-type') && (r.isDataBinary || r.method === 'put')) {

View File

@@ -18,8 +18,8 @@ function getCookies (request) {
}
const cookies = []
for (const cookieName in request.cookies) {
cookies.push(`${cookieName}=${request.cookies[cookieName]}`)
for (const [cookieName, cookieValue] of request.cookies) {
cookies.push(`${cookieName}=${cookieValue}`)
}
return `cookies: [~s|${cookies.join('; ')}|]`
}
@@ -204,6 +204,9 @@ export const _toElixir = request => {
if (!request.urlWithoutQuery.match(/https?:/)) {
request.urlWithoutQuery = 'http://' + request.urlWithoutQuery
}
if (request.cookies) {
util.deleteHeader(request, 'cookie')
}
const template = `request = %HTTPoison.Request{
method: :${request.method},

View File

@@ -18,14 +18,10 @@ export const _toGo = request => {
goCode += '\treq, err := http.NewRequest("' + request.method.toUpperCase() + '", "' + request.url + '", nil)\n'
}
goCode += '\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n'
if (request.headers || request.cookies) {
if (request.headers) {
for (const [headerName, headerValue] of (request.headers || [])) {
goCode += '\treq.Header.Set("' + headerName + '", "' + headerValue + '")\n'
}
if (request.cookies) {
const cookieString = util.serializeCookies(request.cookies)
goCode += '\treq.Header.Set("Cookie", "' + cookieString + '")\n'
}
}
if (request.auth) {

View File

@@ -39,12 +39,6 @@ export const _toJava = request => {
javaCode += '\n'
}
if (request.cookies) {
const cookieString = util.serializeCookies(request.cookies)
javaCode += '\t\thttpConn.setRequestProperty("Cookie", "' + doubleQuotes(cookieString) + '");\n'
javaCode += '\n'
}
if (request.auth) {
javaCode += '\t\tbyte[] message = ("' + doubleQuotes(request.auth.join(':')) + '").getBytes("UTF-8");\n'
javaCode += '\t\tString basicAuth = DatatypeConverter.printBase64Binary(message);\n'

View File

@@ -29,14 +29,14 @@ export const _toJavaScript = request => {
jsFetchCode += 'fetch(\'' + request.url + '\''
if (request.method !== 'get' || request.headers || request.cookies || request.auth || request.body) {
if (request.method !== 'get' || request.headers || request.auth || request.body) {
jsFetchCode += ', {\n'
if (request.method !== 'get') {
jsFetchCode += ' method: \'' + request.method.toUpperCase() + '\''
}
if (request.headers || request.cookies || request.auth) {
if (request.headers || request.auth) {
if (request.method !== 'get') {
jsFetchCode += ',\n'
}
@@ -45,7 +45,7 @@ export const _toJavaScript = request => {
let i = 0
for (const [headerName, headerValue] of (request.headers || [])) {
jsFetchCode += ' \'' + headerName + '\': \'' + headerValue + '\''
if (i < headerCount - 1 || request.cookies || request.auth) {
if (i < headerCount - 1 || request.auth) {
jsFetchCode += ',\n'
}
i++
@@ -54,10 +54,6 @@ export const _toJavaScript = request => {
const [user, password] = request.auth
jsFetchCode += ' \'Authorization\': \'Basic \' + btoa(\'' + user + ':' + password + '\')'
}
if (request.cookies) {
const cookieString = util.serializeCookies(request.cookies)
jsFetchCode += ' \'Cookie\': \'' + cookieString + '\''
}
jsFetchCode += '\n }'
}

View File

@@ -3,23 +3,19 @@ import jsesc from 'jsesc'
export const _toNodeRequest = request => {
let nodeRequestCode = 'var request = require(\'request\');\n\n'
if (request.headers || request.cookies) {
if (request.headers) {
nodeRequestCode += 'var headers = {\n'
const headerCount = request.headers ? request.headers.length : 0
let i = 0
for (const [headerName, headerValue] of (request.headers || [])) {
nodeRequestCode += ' \'' + headerName + '\': \'' + headerValue + '\''
if (i < headerCount - 1 || request.cookies) {
if (i < headerCount - 1) {
nodeRequestCode += ',\n'
} else {
nodeRequestCode += '\n'
}
i++
}
if (request.cookies) {
const cookieString = util.serializeCookies(request.cookies)
nodeRequestCode += ' \'Cookie\': \'' + cookieString + '\'\n'
}
nodeRequestCode += '};\n\n'
}
@@ -37,7 +33,7 @@ export const _toNodeRequest = request => {
nodeRequestCode += ',\n method: \'' + request.method.toUpperCase() + '\''
}
if (request.headers || request.cookies) {
if (request.headers) {
nodeRequestCode += ',\n'
nodeRequestCode += ' headers: headers'
}

View File

@@ -101,12 +101,11 @@ export const _toJsonString = request => {
// }
if (request.cookies) {
const cookies = {}
for (const cookieName in request.cookies) {
cookies[repr(cookieName)] = repr(request.cookies[cookieName])
}
requestJson.cookies = cookies
// TODO: repeated cookies
requestJson.cookies = Object.fromEntries(request.cookies)
// Normally when a generator uses .cookies, it should delete it from
// headers, but users of the JSON output would expect to have all the
// headers in .headers.
}
if (request.headers) {

View File

@@ -153,7 +153,8 @@ const prepareQueryString = (request) => {
const prepareCookies = (request) => {
let response = null
if (request.cookies) {
const cookies = addCellArray(request.cookies, [], '', 1)
// TODO: throws away repeat cookies
const cookies = addCellArray(Object.fromEntries(request.cookies), [], '', 1)
response = setVariableValue('cookies', cookies)
}
return response

View File

@@ -36,6 +36,7 @@ const parseWebOptions = (request) => {
for (const [key, value] of request.headers) {
switch (key) {
case 'User-Agent':
case 'user-agent':
options.UserAgent = value
break
case 'Content-Type':

View File

@@ -18,10 +18,6 @@ export const _toPhpRequests = request => {
}
i++
}
if (request.cookies) {
const cookieString = quote(util.serializeCookies(request.cookies))
headerString += ",\n 'Cookie' => '" + cookieString + "'"
}
headerString += '\n);'
} else {
headerString = '$headers = array();'

View File

@@ -4,6 +4,12 @@ import jsesc from 'jsesc'
const quote = str => jsesc(str, { quotes: 'single' })
export const _toPhp = request => {
let cookieString
if (util.hasHeader(request, 'cookie')) {
cookieString = util.getHeader(request, 'cookie')
util.deleteHeader(request, 'cookie')
}
let phpCode = '<?php\n'
phpCode += '$ch = curl_init();\n'
phpCode += "curl_setopt($ch, CURLOPT_URL, '" + quote(request.url) + "');\n"
@@ -31,8 +37,8 @@ export const _toPhp = request => {
phpCode += 'curl_setopt($ch, CURLOPT_HTTPHEADER, ' + headersArrayCode + ');\n'
}
if (request.cookies) {
phpCode += "curl_setopt($ch, CURLOPT_COOKIE, '" + quote(util.serializeCookies(request.cookies)) + "');\n"
if (cookieString) {
phpCode += "curl_setopt($ch, CURLOPT_COOKIE, '" + quote(cookieString) + "');\n"
}
if (request.auth) {

View File

@@ -216,9 +216,10 @@ export const _toPython = request => {
let cookieDict
if (request.cookies) {
// TODO: could have repeat cookies
cookieDict = 'cookies = {\n'
for (const cookieName in request.cookies) {
const [detectedVars, modifiedString] = detectEnvVar(request.cookies[cookieName])
for (const [cookieName, cookieValue] of request.cookies) {
const [detectedVars, modifiedString] = detectEnvVar(cookieValue)
const hasEnvironmentVariable = detectedVars.size > 0
@@ -229,7 +230,10 @@ export const _toPython = request => {
cookieDict += ' ' + repr(cookieName) + ': ' + reprWithVariable(modifiedString, hasEnvironmentVariable) + ',\n'
}
cookieDict += '}\n'
// TODO: cookieDict should too, to avoid surprises.
commentedOutHeaders.cookie = request.cookies.length > 1 ? 'Requests sorts cookies= alphabetically' : ''
}
let certStr
if (request.cert) {
certStr = 'cert = '
@@ -286,8 +290,10 @@ export const _toPython = request => {
}
let lineStart
if (commentedOutHeaders[headerName.toLowerCase()]) {
headerDict += ' # ' + commentedOutHeaders[headerName.toLowerCase()] + '\n'
if (util.has(commentedOutHeaders, headerName.toLowerCase())) {
if (commentedOutHeaders[headerName.toLowerCase()]) {
headerDict += ' # ' + commentedOutHeaders[headerName.toLowerCase()] + '\n'
}
lineStart = ' # '
} else {
lineStart = ' '

View File

@@ -116,8 +116,10 @@ export const _toR = request => {
let cookieDict
if (request.cookies) {
cookieDict = 'cookies = c(\n'
cookieDict += Object.keys(request.cookies).map(cookieName => ' ' + repr(cookieName) + ' = ' + repr(request.cookies[cookieName])).join(',\n')
cookieDict += request.cookies.map(c => ' ' + repr(c[0]) + ' = ' + repr(c[1])).join(',\n')
// TODO: isn't this an extra \n?
cookieDict += '\n)\n'
util.deleteHeader(request, 'Cookie')
}
let headerDict
if (request.headers) {

View File

@@ -8,11 +8,10 @@ const quote = str => jsesc(str, { quotes: 'double' })
export const _toRust = request => {
const lines = ['extern crate reqwest;']
const hasHeaders = request.headers || request.cookies
{
// Generate imports.
const imports = [
{ want: 'header', condition: hasHeaders },
{ want: 'header', condition: !!request.headers },
{ want: 'multipart', condition: !!request.multipartUploads }
].filter(i => i.condition).map(i => i.want)
@@ -24,19 +23,16 @@ export const _toRust = request => {
}
lines.push('', 'fn main() -> Result<(), Box<dyn std::error::Error>> {')
if (request.headers || request.cookies) {
if (request.headers) {
lines.push(indent('let mut headers = header::HeaderMap::new();'))
const headerEnum = {
cookie: 'header::COOKIE'
}
for (const [headerName, headerValue] of (request.headers || [])) {
lines.push(indent(`headers.insert("${headerName}", "${quote(headerValue)}".parse().unwrap());`))
const enumValue = headerEnum[headerName.toLowerCase()]
const name = enumValue || `"${headerName}"`
lines.push(indent(`headers.insert(${name}, "${quote(headerValue)}".parse().unwrap());`))
}
if (request.cookies) {
const cookies = Object.keys(request.cookies)
.map(key => `${key}=${request.cookies[key]}`)
.join('; ')
lines.push(indent(`headers.insert(header::COOKIE, "${quote(cookies)}".parse().unwrap());`))
}
lines.push('')
}
@@ -66,7 +62,7 @@ export const _toRust = request => {
lines.push(indent(`.basic_auth("${quote(user)}", Some("${quote(password)}"))`, 2))
}
if (hasHeaders) {
if (request.headers) {
lines.push(indent('.headers(headers)', 2))
}

View File

@@ -67,12 +67,6 @@ export const _toStrest = request => {
value
})
}
if (request.cookieString) {
response.requests.curl_converter.request.headers.push({
name: 'Cookie',
value: request.cookieString
})
}
}
if (request.auth) {
const [username, password] = request.auth

View File

@@ -13,9 +13,6 @@ export const ansibleTemplate = `-
{%- for key, value in request.headers %}
{{ key }}: '{{ value }}'
{%- endfor %}
{%- if request.cookieString %}
Cookie: '{{ request.cookieString }}'
{%- endif %}
{%- endif %}
{%- if request.auth %}
{%- set url_username = request.auth[0] %}

110
util.js
View File

@@ -1,6 +1,5 @@
import URL from 'url'
import cookie from 'cookie'
import nunjucks from 'nunjucks'
import parser from './parser.js'
@@ -938,34 +937,41 @@ const buildRequest = parsedArguments => {
let url = parsedArguments.url[parsedArguments.url.length - 1]
let headers
let cookieString
if (parsedArguments.header) {
if (!headers) {
headers = []
}
parsedArguments.header.forEach(header => {
for (const header of parsedArguments.header) {
const [name, value] = header.split(/:(.*)/s, 2)
if (name.toLowerCase().trim().startsWith('cookie') && value.trim()) {
// TODO: this will be overwritten if --cookie is passed
cookieString = header
} else {
headers.push([name, value ? value.replace(/^ /, '') : ''])
}
})
headers.push([name, value ? value.replace(/^ /, '') : ''])
}
}
const capitalizeHeaders = !headers || headers.some(h => h[0] !== h[0].toLowerCase()) || !headers.length
let cookies
const cookieHeaders = (headers || []).filter(h => h[0].toLowerCase() === 'cookie')
if (cookieHeaders.length === 1) {
const parsedCookies = parseCookiesStrict(cookieHeaders[0][1])
if (parsedCookies) {
cookies = parsedCookies
}
} else if (cookieHeaders.length === 0) {
// If there is a Cookie header, --cookies is ignored
if (parsedArguments.cookie) {
// TODO: a --cookie without a = character reads from it as a filename
const cookieString = parsedArguments.cookie.join(';')
headers.push([capitalizeHeaders ? 'Cookie' : 'cookie', cookieString])
cookies = parseCookies(cookieString, false)
}
}
if (parsedArguments['user-agent']) {
if (!headers) {
headers = []
}
// TODO: headers are case insesitive
// detect prevalining case convention of other headers and match it
headers.push(['User-Agent', parsedArguments['user-agent']])
headers.push([capitalizeHeaders ? 'User-Agent' : 'user-agent', parsedArguments['user-agent']])
}
if (parsedArguments.cookie) {
cookieString = parsedArguments.cookie
}
let multipartUploads
if (parsedArguments.form) {
multipartUploads = {}
@@ -977,13 +983,6 @@ const buildRequest = parsedArguments => {
multipartUploads[key] = value
})
}
let cookies
if (cookieString) {
const cookieParseOptions = { decode: (s) => s }
// separate out cookie headers into separate data structure
// note: cookie is case insensitive
cookies = cookie.parse(cookieString.replace(/^Cookie: /gi, ''), cookieParseOptions)
}
// TODO: don't lower case method,
// curl expects you to uppercase always, if you do -X PoSt, that's
@@ -1050,6 +1049,12 @@ const buildRequest = parsedArguments => {
}
}
if (cookies) {
// generators that use .cookies need to do
// deleteHeader(request, 'cookie')
request.cookies = cookies
}
if (parsedArguments.compressed) {
request.compressed = true
}
@@ -1059,10 +1064,6 @@ const buildRequest = parsedArguments => {
}
request.method = method
if (cookies) {
request.cookies = cookies
request.cookieString = cookieString.replace('Cookie: ', '')
}
if (multipartUploads) {
request.multipartUploads = multipartUploads
}
@@ -1170,16 +1171,53 @@ const getHeader = (request, header) => {
}
const hasHeader = (request, header) => {
if (!request.headers) {
return false
}
return !!countHeader(request, header)
}
const deleteHeader = (request, header) => {
const lookup = header.toLowerCase()
for (const h of request.headers) {
if (h[0].toLowerCase() === lookup) {
return true
for (let i = request.headers.length - 1; i >= 0; i--) {
if (request.headers[i][0].toLowerCase() === lookup) {
request.headers.splice(i, 1)
}
}
return false
}
const countHeader = (request, header) => {
let count = 0
const lookup = header.toLowerCase()
for (const h of (request.headers || [])) {
if (h[0].toLowerCase() === lookup) {
count += 1
}
}
return count
}
const parseCookiesStrict = (cookieString) => {
const cookies = []
for (let cookie of cookieString.split(';')) {
cookie = cookie.replace(/^ /, '')
const [name, value] = cookie.split(/=(.*)/s, 2)
if (value === undefined) {
return null
}
cookies.push([name, value])
}
return cookies
}
const parseCookies = (cookieString) => {
const cookies = []
for (let cookie of cookieString.split(';')) {
cookie = cookie.trim()
if (!cookie) {
continue
}
const [name, value] = cookie.split(/=(.*)/s, 2)
cookies.push([name, value || ''])
}
return cookies
}
export {
@@ -1190,5 +1228,7 @@ export {
parseCurlCommand,
serializeCookies,
getHeader,
hasHeader
hasHeader,
deleteHeader,
has
}