Include User-Agent within POST

main
Bob Mottram 2021-06-20 14:39:53 +01:00
parent c76a10480c
commit eab0a92af9
11 changed files with 43 additions and 19 deletions

View File

@ -253,7 +253,8 @@ def sendAnnounceViaServer(baseDir: str, session,
'Content-type': 'application/json',
'Authorization': authHeader
}
postResult = postJson(session, newAnnounceJson, [], inboxUrl,
postResult = postJson(httpPrefix, fromDomainFull,
session, newAnnounceJson, [], inboxUrl,
headers, 3, True)
if not postResult:
print('WARN: announce not posted')
@ -332,7 +333,8 @@ def sendUndoAnnounceViaServer(baseDir: str, session,
'Content-type': 'application/json',
'Authorization': authHeader
}
postResult = postJson(session, unAnnounceJson, [], inboxUrl,
postResult = postJson(httpPrefix, domainFull,
session, unAnnounceJson, [], inboxUrl,
headers, 3, True)
if not postResult:
print('WARN: undo announce not posted')

View File

@ -143,7 +143,8 @@ def sendAvailabilityViaServer(baseDir: str, session,
'Content-type': 'application/json',
'Authorization': authHeader
}
postResult = postJson(session, newAvailabilityJson, [],
postResult = postJson(httpPrefix, domainFull,
session, newAvailabilityJson, [],
inboxUrl, headers, 30, True)
if not postResult:
print('WARN: availability failed to post')

View File

@ -418,7 +418,8 @@ def sendBookmarkViaServer(baseDir: str, session,
'Content-type': 'application/json',
'Authorization': authHeader
}
postResult = postJson(session, newBookmarkJson, [], inboxUrl,
postResult = postJson(httpPrefix, domainFull,
session, newBookmarkJson, [], inboxUrl,
headers, 3, True)
if not postResult:
if debug:
@ -502,7 +503,8 @@ def sendUndoBookmarkViaServer(baseDir: str, session,
'Content-type': 'application/json',
'Authorization': authHeader
}
postResult = postJson(session, newBookmarkJson, [], inboxUrl,
postResult = postJson(httpPrefix, domainFull,
session, newBookmarkJson, [], inboxUrl,
headers, 3, True)
if not postResult:
if debug:

View File

@ -93,7 +93,8 @@ def sendDeleteViaServer(baseDir: str, session,
'Authorization': authHeader
}
postResult = \
postJson(session, newDeleteJson, [], inboxUrl, headers, 3, True)
postJson(httpPrefix, fromDomainFull,
session, newDeleteJson, [], inboxUrl, headers, 3, True)
if not postResult:
if debug:
print('DEBUG: POST delete failed for c2s to ' + inboxUrl)

View File

@ -1029,7 +1029,8 @@ def sendFollowRequestViaServer(baseDir: str, session,
'Authorization': authHeader
}
postResult = \
postJson(session, newFollowJson, [], inboxUrl, headers, 3, True)
postJson(httpPrefix, fromDomainFull,
session, newFollowJson, [], inboxUrl, headers, 3, True)
if not postResult:
if debug:
print('DEBUG: POST follow request failed for c2s to ' + inboxUrl)
@ -1122,7 +1123,8 @@ def sendUnfollowRequestViaServer(baseDir: str, session,
'Authorization': authHeader
}
postResult = \
postJson(session, unfollowJson, [], inboxUrl, headers, 3, True)
postJson(httpPrefix, fromDomainFull,
session, unfollowJson, [], inboxUrl, headers, 3, True)
if not postResult:
if debug:
print('DEBUG: POST unfollow failed for c2s to ' + inboxUrl)

View File

@ -205,7 +205,8 @@ def sendLikeViaServer(baseDir: str, session,
'Content-type': 'application/json',
'Authorization': authHeader
}
postResult = postJson(session, newLikeJson, [], inboxUrl,
postResult = postJson(httpPrefix, fromDomainFull,
session, newLikeJson, [], inboxUrl,
headers, 3, True)
if not postResult:
if debug:
@ -287,7 +288,8 @@ def sendUndoLikeViaServer(baseDir: str, session,
'Content-type': 'application/json',
'Authorization': authHeader
}
postResult = postJson(session, newUndoLikeJson, [], inboxUrl,
postResult = postJson(httpPrefix, fromDomainFull,
session, newUndoLikeJson, [], inboxUrl,
headers, 3, True)
if not postResult:
if debug:

3
pgp.py
View File

@ -588,7 +588,8 @@ def pgpPublicKeyUpload(baseDir: str, session,
tries = 0
while tries < 4:
postResult = \
postJson(session, actorUpdate, [], inboxUrl,
postJson(httpPrefix, domainFull,
session, actorUpdate, [], inboxUrl,
headers, 5, quiet)
if postResult:
break

View File

@ -4198,7 +4198,8 @@ def sendBlockViaServer(baseDir: str, session,
'Content-type': 'application/json',
'Authorization': authHeader
}
postResult = postJson(session, newBlockJson, [], inboxUrl,
postResult = postJson(httpPrefix, fromDomainFull,
session, newBlockJson, [], inboxUrl,
headers, 30, True)
if not postResult:
print('WARN: block unable to post')
@ -4273,7 +4274,8 @@ def sendMuteViaServer(baseDir: str, session,
'Content-type': 'application/json',
'Authorization': authHeader
}
postResult = postJson(session, newMuteJson, [], inboxUrl,
postResult = postJson(httpPrefix, fromDomainFull,
session, newMuteJson, [], inboxUrl,
headers, 3, True)
if postResult is None:
print('WARN: mute unable to post')
@ -4354,7 +4356,8 @@ def sendUndoMuteViaServer(baseDir: str, session,
'Content-type': 'application/json',
'Authorization': authHeader
}
postResult = postJson(session, undoMuteJson, [], inboxUrl,
postResult = postJson(httpPrefix, fromDomainFull,
session, undoMuteJson, [], inboxUrl,
headers, 3, True)
if postResult is None:
print('WARN: undo mute unable to post')
@ -4438,7 +4441,8 @@ def sendUndoBlockViaServer(baseDir: str, session,
'Content-type': 'application/json',
'Authorization': authHeader
}
postResult = postJson(session, newBlockJson, [], inboxUrl,
postResult = postJson(httpPrefix, fromDomainFull,
session, newBlockJson, [], inboxUrl,
headers, 30, True)
if not postResult:
print('WARN: unblock unable to post')

View File

@ -149,7 +149,8 @@ def getJson(session, url: str, headers: {}, params: {}, debug: bool,
return None
def postJson(session, postJsonObject: {}, federationList: [],
def postJson(httpPrefix: str, domainFull: str,
session, postJsonObject: {}, federationList: [],
inboxUrl: str, headers: {}, timeoutSec: int = 60,
quiet: bool = False) -> str:
"""Post a json message to the inbox of another person
@ -160,6 +161,11 @@ def postJson(session, postJsonObject: {}, federationList: [],
print('postJson: ' + inboxUrl + ' not permitted')
return None
sessionHeaders = headers
sessionHeaders['User-Agent'] = 'Epicyon/' + __version__
sessionHeaders['User-Agent'] += \
'; +' + httpPrefix + '://' + domainFull + '/'
try:
postResult = \
session.post(url=inboxUrl,

View File

@ -410,7 +410,8 @@ def sendShareViaServer(baseDir, session,
'Authorization': authHeader
}
postResult = \
postJson(session, newShareJson, [], inboxUrl, headers, 30, True)
postJson(httpPrefix, fromDomainFull,
session, newShareJson, [], inboxUrl, headers, 30, True)
if not postResult:
if debug:
print('DEBUG: POST share failed for c2s to ' + inboxUrl)
@ -500,7 +501,8 @@ def sendUndoShareViaServer(baseDir: str, session,
'Authorization': authHeader
}
postResult = \
postJson(session, undoShareJson, [], inboxUrl,
postJson(httpPrefix, fromDomainFull,
session, undoShareJson, [], inboxUrl,
headers, 30, True)
if not postResult:
if debug:

View File

@ -246,7 +246,8 @@ def sendSkillViaServer(baseDir: str, session, nickname: str, password: str,
'Authorization': authHeader
}
postResult = \
postJson(session, newSkillJson, [], inboxUrl,
postJson(httpPrefix, domainFull,
session, newSkillJson, [], inboxUrl,
headers, 30, True)
if not postResult:
if debug: