mirror of
https://github.com/curlconverter/curlconverter.git
synced 2022-05-22 02:35:29 +03:00
handle charset=UTF-8 in Content-Type header (#356)
This commit is contained in:
committed by
GitHub
parent
4129d6b885
commit
7595e8b94f
52
fixtures/python/post_data_binary_with_equals.py
generated
52
fixtures/python/post_data_binary_with_equals.py
generated
@@ -46,6 +46,54 @@ params = {
|
||||
'AC': '1',
|
||||
}
|
||||
|
||||
data = '{"__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"}}'
|
||||
json_data = {
|
||||
'__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': None,
|
||||
'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',
|
||||
},
|
||||
}
|
||||
|
||||
response = requests.post('https://localhost/api/service.svc', headers=headers, params=params, cookies=cookies, data=data)
|
||||
response = requests.post('https://localhost/api/service.svc', headers=headers, params=params, cookies=cookies, json=json_data)
|
||||
|
||||
@@ -91,7 +91,9 @@ function getDataString (request) {
|
||||
|
||||
const dataString = 'data = ' + repr(request.data) + '\n'
|
||||
|
||||
if (util.getHeader(request, 'content-type') === 'application/json') {
|
||||
const isJson = util.hasHeader(request, 'content-type') &&
|
||||
util.getHeader(request, 'content-type').split(';')[0].trim() === 'application/json'
|
||||
if (isJson) {
|
||||
try {
|
||||
const dataAsJson = JSON.parse(request.data)
|
||||
// TODO: we actually want to know how it's serialized by
|
||||
@@ -302,7 +304,7 @@ export const _toPython = request => {
|
||||
[dataString, jsonDataString, jsonDataStringRoundtrips] = getDataString(request)
|
||||
// Remove "Content-Type" from the headers dict
|
||||
// because Requests adds it automatically when you use json=
|
||||
if (jsonDataString) {
|
||||
if (jsonDataString && util.getHeader(request, 'content-type').trim() === 'application/json') {
|
||||
commentedOutHeaders['content-type'] = 'Already added when you pass json='
|
||||
if (!jsonDataStringRoundtrips) {
|
||||
commentedOutHeaders['content-type'] += ' but not when you pass data='
|
||||
@@ -314,7 +316,10 @@ export const _toPython = request => {
|
||||
// If you manually pass a Content-Type header it won't set a `boundary`
|
||||
// wheras curl does, so the request will fail.
|
||||
// https://github.com/curlconverter/curlconverter/issues/248
|
||||
if (filesString && util.getHeader(request, 'content-type') === 'multipart/form-data') {
|
||||
if (filesString &&
|
||||
util.hasHeader(request, 'content-type') &&
|
||||
util.getHeader(request, 'content-type').trim() === 'multipart/form-data' &&
|
||||
!util.getHeader(request, 'content-type').includes('boundary=')) {
|
||||
// TODO: better wording
|
||||
commentedOutHeaders['content-type'] = "requests won't add a boundary if this header is set when you pass files="
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user