Browse Source

Include character encoding in content-type http header

Bob Mottram 11 months ago
parent
commit
2b884be142
14 changed files with 90 additions and 88 deletions
  1. 1 1
      announce.py
  2. 1 1
      availability.py
  3. 2 2
      blocking.py
  4. 66 66
      daemon.py
  5. 1 1
      delete.py
  6. 2 2
      follow.py
  7. 3 3
      httpsig.py
  8. 2 2
      like.py
  9. 2 2
      posts.py
  10. 2 1
      roles.py
  11. 1 1
      session.py
  12. 2 2
      shares.py
  13. 1 1
      skills.py
  14. 4 3
      tests.py

+ 1 - 1
announce.py

@@ -501,7 +501,7 @@ def sendAnnounceViaServer(baseDir: str,session, \
     authHeader=createBasicAuthHeader(fromNickname,password)
      
     headers = {'host': fromDomain, \
-               'Content-type': 'application/json', \
+               'Content-type': 'application/json; charset=utf-8', \
                'Authorization': authHeader}
     postResult = \
         postJson(session,newAnnounceJson,[],inboxUrl,headers,"inbox:write")

+ 1 - 1
availability.py

@@ -130,7 +130,7 @@ def sendAvailabilityViaServer(baseDir: str,session, \
     authHeader=createBasicAuthHeader(Nickname,password)
      
     headers = {'host': domain, \
-               'Content-type': 'application/json', \
+               'Content-type': 'application/json; charset=utf-8', \
                'Authorization': authHeader}
     postResult = \
         postJson(session,newAvailabilityJson,[],inboxUrl,headers,"inbox:write")

+ 2 - 2
blocking.py

@@ -214,7 +214,7 @@ def sendBlockViaServer(baseDir: str,session, \
     authHeader=createBasicAuthHeader(fromNickname,password)
      
     headers = {'host': fromDomain, \
-               'Content-type': 'application/json', \
+               'Content-type': 'application/json; charset=utf-8', \
                'Authorization': authHeader}
     postResult = \
         postJson(session,newBlockJson,[],inboxUrl,headers,"inbox:write")
@@ -291,7 +291,7 @@ def sendUndoBlockViaServer(baseDir: str,session, \
     authHeader=createBasicAuthHeader(fromNickname,password)
      
     headers = {'host': fromDomain, \
-               'Content-type': 'application/json', \
+               'Content-type': 'application/json; charset=utf-8', \
                'Authorization': authHeader}
     postResult = \
         postJson(session,newBlockJson,[],inboxUrl,headers,"inbox:write")

+ 66 - 66
daemon.py

@@ -333,7 +333,7 @@ class PubServer(BaseHTTPRequestHandler):
             wfResult=webfingerMeta(self.server.httpPrefix,self.server.domainFull)
             if wfResult:
                 msg=wfResult.encode('utf-8')
-                self._set_headers('application/xrd+xml',len(msg),None)
+                self._set_headers('application/xrd+xml; charset=utf-8',len(msg),None)
                 self._write(msg)
             return
 
@@ -342,7 +342,7 @@ class PubServer(BaseHTTPRequestHandler):
         wfResult=webfingerLookup(self.path,self.server.baseDir,self.server.port,self.server.debug)
         if wfResult:
             msg=json.dumps(wfResult).encode('utf-8')
-            self._set_headers('application/jrd+json',len(msg),None)
+            self._set_headers('application/jrd+json; charset=utf-8',len(msg),None)
             self._write(msg)
         else:
             if self.server.debug:
@@ -706,7 +706,7 @@ class PubServer(BaseHTTPRequestHandler):
         if self.path=='/logout':
             msg=htmlLogin(self.server.translate, \
                           self.server.baseDir,False).encode('utf-8')
-            self._logout_headers('text/html',len(msg))
+            self._logout_headers('text/html; charset=utf-8',len(msg))
             self._write(msg)            
             return
         
@@ -785,7 +785,7 @@ class PubServer(BaseHTTPRequestHandler):
                                          optionsProfileUrl, \
                                          optionsLink, \
                                          pageNumber,donateUrl).encode()
-                   self._set_headers('text/html',len(msg),cookie)
+                   self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                    self._write(msg)
                    self.server.GETbusy=False
                    return
@@ -807,7 +807,7 @@ class PubServer(BaseHTTPRequestHandler):
                self._redirect_headers(actor+'/inbox',cookie)
                self.server.GETbusy=False
                return                
-            self._set_headers('text/html',len(msg),cookie)
+            self._set_headers('text/html; charset=utf-8',len(msg),cookie)
             self._write(msg)
             self.server.GETbusy=False
             return
@@ -816,7 +816,7 @@ class PubServer(BaseHTTPRequestHandler):
             msg=htmlTermsOfService(self.server.baseDir, \
                                    self.server.httpPrefix, \
                                    self.server.domainFull).encode()
-            self._login_headers('text/html',len(msg))
+            self._login_headers('text/html; charset=utf-8',len(msg))
             self._write(msg)
             self.server.GETbusy=False
             return
@@ -825,7 +825,7 @@ class PubServer(BaseHTTPRequestHandler):
             msg=htmlAbout(self.server.baseDir, \
                           self.server.httpPrefix, \
                           self.server.domainFull).encode()
-            self._login_headers('text/html',len(msg))
+            self._login_headers('text/html; charset=utf-8',len(msg))
             self._write(msg)
             self.server.GETbusy=False
             return
@@ -884,7 +884,7 @@ class PubServer(BaseHTTPRequestHandler):
                         time.sleep(1)
                         tries+=1
                 msg=css.encode('utf-8')
-                self._set_headers('text/css',len(msg),cookie)
+                self._set_headers('text/css; charset=utf-8',len(msg),cookie)
                 self._write(msg)
                 return
 
@@ -1142,7 +1142,7 @@ class PubServer(BaseHTTPRequestHandler):
             # request basic auth
             msg=htmlLogin(self.server.translate, \
                           self.server.baseDir).encode('utf-8')
-            self._login_headers('text/html',len(msg))
+            self._login_headers('text/html; charset=utf-8',len(msg))
             self._write(msg)
             self.server.GETbusy=False
             return
@@ -1159,7 +1159,7 @@ class PubServer(BaseHTTPRequestHandler):
                 hashtag=hashtag.split('?page=')[0]
             if isBlockedHashtag(self.server.baseDir,hashtag):
                 msg=htmlHashtagBlocked(self.server.baseDir).encode('utf-8')
-                self._login_headers('text/html',len(msg))
+                self._login_headers('text/html; charset=utf-8',len(msg))
                 self._write(msg)
                 self.server.GETbusy=False
                 return
@@ -1173,7 +1173,7 @@ class PubServer(BaseHTTPRequestHandler):
                                   self.server.projectVersion)
             if hashtagStr:
                 msg=hashtagStr.encode()
-                self._set_headers('text/html',len(msg),cookie)
+                self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                 self._write(msg)
             else:
                 originPathStr=self.path.split('/tags/')[0]
@@ -1188,7 +1188,7 @@ class PubServer(BaseHTTPRequestHandler):
                # show the search screen
                msg=htmlSearch(self.server.translate, \
                               self.server.baseDir,self.path).encode()
-               self._set_headers('text/html',len(msg),cookie)
+               self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                self._write(msg)
                self.server.GETbusy=False
                return
@@ -1201,7 +1201,7 @@ class PubServer(BaseHTTPRequestHandler):
                                 self.server.baseDir,self.path, \
                                 self.server.httpPrefix, \
                                 self.server.domainFull).encode()
-               self._set_headers('text/html',len(msg),cookie)
+               self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                self._write(msg)
                self.server.GETbusy=False
                return
@@ -1213,7 +1213,7 @@ class PubServer(BaseHTTPRequestHandler):
                msg=htmlSearchEmojiTextEntry(self.server.translate, \
                                             self.server.baseDir, \
                                             self.path).encode()
-               self._set_headers('text/html',len(msg),cookie)
+               self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                self._write(msg)
                self.server.GETbusy=False
                return
@@ -1515,7 +1515,7 @@ class PubServer(BaseHTTPRequestHandler):
                                    __version__,self.server.cachedWebfingers, \
                                    self.server.personCache)
                 if deleteStr:
-                    self._set_headers('text/html',len(deleteStr),cookie)
+                    self._set_headers('text/html; charset=utf-8',len(deleteStr),cookie)
                     self._write(deleteStr.encode())
                     self.server.GETbusy=False
                     return
@@ -1596,7 +1596,7 @@ class PubServer(BaseHTTPRequestHandler):
                                     self.server.baseDir, \
                                     self.path,self.server.domain, \
                                     self.server.port).encode()
-                self._set_headers('text/html',len(msg),cookie)
+                self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                 self._write(msg)
                 self.server.GETbusy=False
                 return
@@ -1615,7 +1615,7 @@ class PubServer(BaseHTTPRequestHandler):
                                 replyToList, \
                                 shareDescription, \
                                 replyPageNumber).encode()
-                self._set_headers('text/html',len(msg),cookie)
+                self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                 self._write(msg)
                 self.server.GETbusy=False
                 return
@@ -1662,12 +1662,12 @@ class PubServer(BaseHTTPRequestHandler):
                                                            authorized,postJsonObject, \
                                                            self.server.httpPrefix, \
                                                            self.server.projectVersion).encode('utf-8')
-                                    self._set_headers('text/html',len(msg),cookie)                    
+                                    self._set_headers('text/html; charset=utf-8',len(msg),cookie)                    
                                     self._write(msg)
                                 else:
                                     if self._fetchAuthenticated():
                                         msg=json.dumps(postJsonObject).encode('utf-8')
-                                        self._set_headers('application/json',len(msg),None)
+                                        self._set_headers('application/json; charset=utf-8',len(msg),None)
                                         self._write(msg)
                                     else:
                                         self._404()
@@ -1727,14 +1727,14 @@ class PubServer(BaseHTTPRequestHandler):
                                                             repliesJson, \
                                                             self.server.httpPrefix, \
                                                             self.server.projectVersion).encode('utf-8')
-                                        self._set_headers('text/html',len(msg),cookie)
+                                        self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                                         print('----------------------------------------------------')
                                         #pprint(repliesJson)
                                         self._write(msg)
                                     else:
                                         if self._fetchAuthenticated():
                                             msg=json.dumps(repliesJson).encode('utf-8')
-                                            self._set_headers('application/json',len(msg),None)
+                                            self._set_headers('application/json; charset=utf-8',len(msg),None)
                                             self._write(msg)
                                         else:
                                             self._404()
@@ -1778,12 +1778,12 @@ class PubServer(BaseHTTPRequestHandler):
                                                             repliesJson, \
                                                             self.server.httpPrefix, \
                                                             self.server.projectVersion).encode('utf-8')
-                                        self._set_headers('text/html',len(msg),cookie)
+                                        self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                                         self._write(msg)
                                     else:
                                         if self._fetchAuthenticated():
                                             msg=json.dumps(repliesJson).encode('utf-8')
-                                            self._set_headers('application/json',len(msg),None)
+                                            self._set_headers('application/json; charset=utf-8',len(msg),None)
                                             self._write(msg)
                                         else:
                                             self._404()
@@ -1820,12 +1820,12 @@ class PubServer(BaseHTTPRequestHandler):
                                                     self.server.personCache, \
                                                     actorJson['roles'], \
                                                     None,None).encode('utf-8')
-                                    self._set_headers('text/html',len(msg),cookie)
+                                    self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                                     self._write(msg)
                             else:
                                 if self._fetchAuthenticated():
                                     msg=json.dumps(actorJson['roles']).encode('utf-8')
-                                    self._set_headers('application/json',len(msg),None)
+                                    self._set_headers('application/json; charset=utf-8',len(msg),None)
                                     self._write(msg)
                                 else:
                                     self._404()
@@ -1863,12 +1863,12 @@ class PubServer(BaseHTTPRequestHandler):
                                                     self.server.personCache, \
                                                     actorJson['skills'], \
                                                     None,None).encode('utf-8')
-                                    self._set_headers('text/html',len(msg),cookie)
+                                    self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                                     self._write(msg)
                             else:
                                 if self._fetchAuthenticated():
                                     msg=json.dumps(actorJson['skills']).encode('utf-8')
-                                    self._set_headers('application/json',len(msg),None)
+                                    self._set_headers('application/json; charset=utf-8',len(msg),None)
                                     self._write(msg)
                                 else:
                                     self._404()
@@ -1919,12 +1919,12 @@ class PubServer(BaseHTTPRequestHandler):
                                                            authorized,postJsonObject, \
                                                            self.server.httpPrefix, \
                                                            self.server.projectVersion).encode('utf-8')
-                                    self._set_headers('text/html',len(msg),cookie)
+                                    self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                                     self._write(msg)
                                 else:
                                     if self._fetchAuthenticated():
                                         msg=json.dumps(postJsonObject).encode('utf-8')
-                                        self._set_headers('application/json',len(msg),None)
+                                        self._set_headers('application/json; charset=utf-8',len(msg),None)
                                         self._write(msg)
                                     else:
                                         self._404()
@@ -1981,13 +1981,13 @@ class PubServer(BaseHTTPRequestHandler):
                                           self.server.allowDeletion, \
                                           self.server.httpPrefix, \
                                           self.server.projectVersion).encode('utf-8')
-                            self._set_headers('text/html',len(msg),cookie)
+                            self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                             self._write(msg)
                         else:
                             # don't need authenticated fetch here because there is
                             # already the authorization check
                             msg=json.dumps(inboxFeed).encode('utf-8')
-                            self._set_headers('application/json',len(msg),None)
+                            self._set_headers('application/json; charset=utf-8',len(msg),None)
                             self._write(msg)
                         self.server.GETbusy=False
                         return
@@ -2051,13 +2051,13 @@ class PubServer(BaseHTTPRequestHandler):
                                              self.server.allowDeletion, \
                                              self.server.httpPrefix, \
                                              self.server.projectVersion).encode('utf-8')
-                            self._set_headers('text/html',len(msg),cookie)
+                            self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                             self._write(msg)
                         else:
                             # don't need authenticated fetch here because there is
                             # already the authorization check
                             msg=json.dumps(inboxDMFeed).encode('utf-8')
-                            self._set_headers('application/json',len(msg),None)
+                            self._set_headers('application/json; charset=utf-8',len(msg),None)
                             self._write(msg)
                         self.server.GETbusy=False
                         return
@@ -2124,13 +2124,13 @@ class PubServer(BaseHTTPRequestHandler):
                                              self.server.allowDeletion, \
                                              self.server.httpPrefix, \
                                              self.server.projectVersion).encode('utf-8')
-                        self._set_headers('text/html',len(msg),cookie)
+                        self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                         self._write(msg)
                     else:
                         # don't need authenticated fetch here because there is
                         # already the authorization check
                         msg=json.dumps(inboxRepliesFeed).encode('utf-8')
-                        self._set_headers('application/json',len(msg),None)
+                        self._set_headers('application/json; charset=utf-8',len(msg),None)
                         self._write(msg)
                     self.server.GETbusy=False
                     return
@@ -2197,13 +2197,13 @@ class PubServer(BaseHTTPRequestHandler):
                                            self.server.allowDeletion, \
                                            self.server.httpPrefix, \
                                            self.server.projectVersion).encode('utf-8')
-                        self._set_headers('text/html',len(msg),cookie)
+                        self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                         self._write(msg)
                     else:
                         # don't need authenticated fetch here because there is
                         # already the authorization check
                         msg=json.dumps(inboxMediaFeed).encode('utf-8')
-                        self._set_headers('application/json',len(msg),None)
+                        self._set_headers('application/json; charset=utf-8',len(msg),None)
                         self._write(msg)
                     self.server.GETbusy=False
                     return
@@ -2247,7 +2247,7 @@ class PubServer(BaseHTTPRequestHandler):
                                        self.server.allowDeletion, \
                                        self.server.httpPrefix, \
                                        self.server.projectVersion).encode('utf-8')
-                        self._set_headers('text/html',len(msg),cookie)
+                        self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                         self._write(msg)
                         self.server.GETbusy=False
                         return
@@ -2303,12 +2303,12 @@ class PubServer(BaseHTTPRequestHandler):
                                self.server.allowDeletion, \
                                self.server.httpPrefix, \
                                self.server.projectVersion).encode('utf-8')
-                self._set_headers('text/html',len(msg),cookie)
+                self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                 self._write(msg)
             else:
                 if self._fetchAuthenticated():
                     msg=json.dumps(outboxFeed).encode('utf-8')
-                    self._set_headers('application/json',len(msg),None)
+                    self._set_headers('application/json; charset=utf-8',len(msg),None)
                     self._write(msg)
                 else:
                     self._404()
@@ -2365,13 +2365,13 @@ class PubServer(BaseHTTPRequestHandler):
                                                True, \
                                                self.server.httpPrefix, \
                                                self.server.projectVersion).encode('utf-8')
-                            self._set_headers('text/html',len(msg),cookie)
+                            self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                             self._write(msg)
                         else:
                             # don't need authenticated fetch here because there is
                             # already the authorization check
                             msg=json.dumps(moderationFeed).encode('utf-8')
-                            self._set_headers('application/json',len(msg),None)
+                            self._set_headers('application/json; charset=utf-8',len(msg),None)
                             self._write(msg)
                         self.server.GETbusy=False
                         return
@@ -2434,14 +2434,14 @@ class PubServer(BaseHTTPRequestHandler):
                                     self.server.personCache, \
                                     shares, \
                                     pageNumber,sharesPerPage).encode('utf-8')
-                    self._set_headers('text/html',len(msg),cookie)
+                    self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                     self._write(msg)
                     self.server.GETbusy=False
                     return
             else:
                 if self._fetchAuthenticated():
                     msg=json.dumps(shares).encode('utf-8')
-                    self._set_headers('application/json',len(msg),None)
+                    self._set_headers('application/json; charset=utf-8',len(msg),None)
                     self._write(msg)
                 else:
                     self._404()
@@ -2490,14 +2490,14 @@ class PubServer(BaseHTTPRequestHandler):
                                     self.server.personCache, \
                                     following, \
                                     pageNumber,followsPerPage).encode('utf-8')
-                    self._set_headers('text/html',len(msg),cookie)
+                    self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                     self._write(msg)
                     self.server.GETbusy=False
                     return
             else:
                 if self._fetchAuthenticated():
                     msg=json.dumps(following).encode('utf-8')
-                    self._set_headers('application/json',len(msg),None)
+                    self._set_headers('application/json; charset=utf-8',len(msg),None)
                     self._write(msg)
                 else:
                     self._404()
@@ -2545,14 +2545,14 @@ class PubServer(BaseHTTPRequestHandler):
                                     self.server.personCache, \
                                     followers, \
                                     pageNumber,followsPerPage).encode('utf-8')
-                    self._set_headers('text/html',len(msg),cookie)
+                    self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                     self._write(msg)
                     self.server.GETbusy=False
                     return
             else:
                 if self._fetchAuthenticated():
                     msg=json.dumps(followers).encode('utf-8')
-                    self._set_headers('application/json',len(msg),None)
+                    self._set_headers('application/json; charset=utf-8',len(msg),None)
                     self._write(msg)
                 else:
                     self._404()
@@ -2580,12 +2580,12 @@ class PubServer(BaseHTTPRequestHandler):
                                 self.server.cachedWebfingers, \
                                 self.server.personCache, \
                                 None,None).encode('utf-8')
-                self._set_headers('text/html',len(msg),cookie)
+                self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                 self._write(msg)
             else:
                 if self._fetchAuthenticated():
                     msg=json.dumps(getPerson).encode('utf-8')
-                    self._set_headers('application/json',len(msg),None)
+                    self._set_headers('application/json; charset=utf-8',len(msg),None)
                     self._write(msg)
                 else:
                     self._404()
@@ -2611,7 +2611,7 @@ class PubServer(BaseHTTPRequestHandler):
                 content = File.read()
                 contentJson=json.loads(content)
                 msg=json.dumps(contentJson).encode('utf-8')
-                self._set_headers('application/json',len(msg),None)
+                self._set_headers('application/json; charset=utf-8',len(msg),None)
                 self._write(msg)
         else:
             if self.server.debug:
@@ -2620,7 +2620,7 @@ class PubServer(BaseHTTPRequestHandler):
         self.server.GETbusy=False
 
     def do_HEAD(self):
-        self._set_headers('application/json',0,None)
+        self._set_headers('application/json; charset=utf-8',0,None)
 
     def _receiveNewPostProcess(self,authorized: bool, \
                                postType: str,path: str,headers: {}) -> int:
@@ -3039,7 +3039,7 @@ class PubServer(BaseHTTPRequestHandler):
                 else:
                     if isSuspended(self.server.baseDir,loginNickname):
                         msg=htmlSuspended(self.server.baseDir).encode('utf-8')
-                        self._login_headers('text/html',len(msg))
+                        self._login_headers('text/html; charset=utf-8',len(msg))
                         self._write(msg)
                         self.server.POSTbusy=False
                         return                 
@@ -3415,7 +3415,7 @@ class PubServer(BaseHTTPRequestHandler):
                     elif moderationStr.startswith('submitInfo'):
                         msg=htmlModerationInfo(self.server.translate, \
                                                self.server.baseDir).encode('utf-8')
-                        self._login_headers('text/html',len(msg))
+                        self._login_headers('text/html; charset=utf-8',len(msg))
                         self._write(msg)
                         self.server.POSTbusy=False
                         return                        
@@ -3616,7 +3616,7 @@ class PubServer(BaseHTTPRequestHandler):
                                           self.server.projectVersion)
                     if hashtagStr:
                         msg=hashtagStr.encode('utf-8')
-                        self._login_headers('text/html',len(msg))
+                        self._login_headers('text/html; charset=utf-8',len(msg))
                         self._write(msg)
                         self.server.POSTbusy=False
                         return
@@ -3630,7 +3630,7 @@ class PubServer(BaseHTTPRequestHandler):
                                          64)
                     if skillStr:
                         msg=skillStr.encode('utf-8')
-                        self._login_headers('text/html',len(msg))
+                        self._login_headers('text/html; charset=utf-8',len(msg))
                         self._write(msg)
                         self.server.POSTbusy=False
                         return
@@ -3657,7 +3657,7 @@ class PubServer(BaseHTTPRequestHandler):
                                                self.server.projectVersion)
                     if profileStr:
                         msg=profileStr.encode('utf-8')
-                        self._login_headers('text/html',len(msg))
+                        self._login_headers('text/html; charset=utf-8',len(msg))
                         self._write(msg)
                         self.server.POSTbusy=False
                         return
@@ -3677,7 +3677,7 @@ class PubServer(BaseHTTPRequestHandler):
                                         self.server.baseDir,searchStr)
                     if emojiStr:
                         msg=emojiStr.encode('utf-8')
-                        self._login_headers('text/html',len(msg))
+                        self._login_headers('text/html; charset=utf-8',len(msg))
                         self._write(msg)
                         self.server.POSTbusy=False
                         return
@@ -3693,7 +3693,7 @@ class PubServer(BaseHTTPRequestHandler):
                                               actorStr)
                     if sharedItemsStr:
                         msg=sharedItemsStr.encode('utf-8')
-                        self._login_headers('text/html',len(msg))
+                        self._login_headers('text/html; charset=utf-8',len(msg))
                         self._write(msg)
                         self.server.POSTbusy=False
                         return
@@ -4026,7 +4026,7 @@ class PubServer(BaseHTTPRequestHandler):
                                        originPathStr, \
                                        optionsActor, \
                                        optionsAvatarUrl).encode()
-                self._set_headers('text/html',len(msg),cookie)
+                self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                 self._write(msg)
                 self.server.POSTbusy=False
                 return
@@ -4038,7 +4038,7 @@ class PubServer(BaseHTTPRequestHandler):
                                       originPathStr, \
                                       optionsActor, \
                                       optionsAvatarUrl).encode()
-                self._set_headers('text/html',len(msg),cookie)
+                self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                 self._write(msg)
                 self.server.POSTbusy=False
                 return
@@ -4050,7 +4050,7 @@ class PubServer(BaseHTTPRequestHandler):
                                         originPathStr, \
                                         optionsActor, \
                                         optionsAvatarUrl).encode()
-                self._set_headers('text/html',len(msg),cookie)
+                self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                 self._write(msg)
                 self.server.POSTbusy=False
                 return
@@ -4063,7 +4063,7 @@ class PubServer(BaseHTTPRequestHandler):
                                 reportPath,None, \
                                 [optionsActor],None, \
                                 pageNumber).encode()
-                self._set_headers('text/html',len(msg),cookie)
+                self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                 self._write(msg)
                 self.server.POSTbusy=False
                 return            
@@ -4095,7 +4095,7 @@ class PubServer(BaseHTTPRequestHandler):
                                 self.server.baseDir, \
                                 reportPath,None,[], \
                                 postUrl,pageNumber).encode()
-                self._set_headers('text/html',len(msg),cookie)
+                self._set_headers('text/html; charset=utf-8',len(msg),cookie)
                 self._write(msg)
                 self.server.POSTbusy=False
                 return            
@@ -4247,8 +4247,8 @@ class PubServer(BaseHTTPRequestHandler):
             return            
 
         # refuse to receive non-json content
-        if self.headers['Content-type'] != 'application/json' and \
-           self.headers['Content-type'] != 'application/activity+json':
+        if 'application/json' not in self.headers['Content-type'] and \
+           'application/activity+json' not in self.headers['Content-type']:
             print("POST is not json: "+self.headers['Content-type'])
             if self.server.debug:
                 print(str(self.headers))

+ 1 - 1
delete.py

@@ -144,7 +144,7 @@ def sendDeleteViaServer(baseDir: str,session, \
     authHeader=createBasicAuthHeader(fromNickname,password)
      
     headers = {'host': fromDomain, \
-               'Content-type': 'application/json', \
+               'Content-type': 'application/json; charset=utf-8', \
                'Authorization': authHeader}
     postResult = \
         postJson(session,newDeleteJson,[],inboxUrl,headers,"inbox:write")

+ 2 - 2
follow.py

@@ -733,7 +733,7 @@ def sendFollowRequestViaServer(baseDir: str,session, \
     authHeader=createBasicAuthHeader(fromNickname,password)
      
     headers = {'host': fromDomain, \
-               'Content-type': 'application/json', \
+               'Content-type': 'application/json; charset=utf-8', \
                'Authorization': authHeader}
     postResult = \
         postJson(session,newFollowJson,[],inboxUrl,headers,"inbox:write")
@@ -818,7 +818,7 @@ def sendUnfollowRequestViaServer(baseDir: str,session, \
     authHeader=createBasicAuthHeader(fromNickname,password)
      
     headers = {'host': fromDomain, \
-               'Content-type': 'application/json', \
+               'Content-type': 'application/json; charset=utf-8', \
                'Authorization': authHeader}
     postResult = \
         postJson(session,unfollowJson,[],inboxUrl,headers,"inbox:write")

+ 3 - 3
httpsig.py

@@ -47,10 +47,10 @@ def signPostHeaders(dateStr: str,privateKeyPem: str, \
         dateStr=strftime("%a, %d %b %Y %H:%M:%S %Z", gmtime())
     keyID=httpPrefix+'://'+domain+'/users/'+nickname+'#main-key'
     if not messageBodyJsonStr:
-        headers={'(request-target)': f'post {path}','host': toDomain,'date': dateStr,'content-type': 'application/json'}
+        headers={'(request-target)': f'post {path}','host': toDomain,'date': dateStr,'content-type': 'application/json; charset=utf-8'}
     else:
         bodyDigest=messageContentDigest(messageBodyJsonStr)
-        headers={'(request-target)': f'post {path}','host': toDomain,'date': dateStr,'digest': f'SHA-256={bodyDigest}','content-type': 'application/activity+json'}
+        headers={'(request-target)': f'post {path}','host': toDomain,'date': dateStr,'digest': f'SHA-256={bodyDigest}','content-type': 'application/activity+json; charset=utf-8'}
     privateKeyPem=RSA.import_key(privateKeyPem)
     #headers.update({
     #    '(request-target)': f'post {path}',
@@ -87,7 +87,7 @@ def createSignedHeader(privateKeyPem: str,nickname: str, \
                        messageBodyJsonStr: str) -> {}:
     """Note that the domain is the destination, not the sender
     """
-    contentType='application/activity+json'
+    contentType='application/activity+json; charset=utf-8'
     headerDomain=toDomain
 
     if toPort:

+ 2 - 2
like.py

@@ -402,7 +402,7 @@ def sendLikeViaServer(baseDir: str,session, \
     authHeader=createBasicAuthHeader(fromNickname,password)
      
     headers = {'host': fromDomain, \
-               'Content-type': 'application/json', \
+               'Content-type': 'application/json; charset=utf-8', \
                'Authorization': authHeader}
     postResult = \
         postJson(session,newLikeJson,[],inboxUrl,headers,"inbox:write")
@@ -481,7 +481,7 @@ def sendUndoLikeViaServer(baseDir: str,session, \
     authHeader=createBasicAuthHeader(fromNickname,password)
      
     headers = {'host': fromDomain, \
-               'Content-type': 'application/json', \
+               'Content-type': 'application/json; charset=utf-8', \
                'Authorization': authHeader}
     postResult = \
         postJson(session,newUndoLikeJson,[],inboxUrl,headers,"inbox:write")

+ 2 - 2
posts.py

@@ -120,7 +120,7 @@ def getUserUrl(wfRequest: {}) -> str:
     if wfRequest.get('links'):
         for link in wfRequest['links']:
             if link.get('type') and link.get('href'):
-                if link['type'] == 'application/activity+json':
+                if 'application/activity+json' in link['type']:
                     if not ('/users/' in link['href'] or \
                             '/profile/' in link['href'] or \
                             '/channel/' in link['href']):
@@ -1250,7 +1250,7 @@ def sendPostViaServer(projectVersion: str, \
         #    return 9
      
     headers = {'host': fromDomain, \
-               'Content-type': 'application/json', \
+               'Content-type': 'application/json; charset=utf-8', \
                'Authorization': authHeader}
     postResult = \
         postJsonString(session,json.dumps(postJsonObject),[],inboxUrl,headers,"inbox:write",debug)

+ 2 - 1
roles.py

@@ -281,7 +281,7 @@ def sendRoleViaServer(baseDir: str,session, \
     authHeader=createBasicAuthHeader(delegatorNickname,password)
      
     headers = {'host': delegatorDomain, \
-               'Content-type': 'application/json', \
+               'Content-type': 'application/json; charset=utf-8', \
                'Authorization': authHeader}
     postResult = \
         postJson(session,newRoleJson,[],inboxUrl,headers,"inbox:write")
@@ -294,3 +294,4 @@ def sendRoleViaServer(baseDir: str,session, \
         print('DEBUG: c2s POST role success')
 
     return newRoleJson
+

+ 1 - 1
session.py

@@ -96,7 +96,7 @@ def postJsonString(session,postJsonStr: str, \
     postResult = session.post(url = inboxUrl, data = postJsonStr, headers=headers)
     if postResult.status_code<200 or postResult.status_code>202:
         #if postResult.status_code==400:
-        #    headers['content-type']='application/ld+json'
+        #    headers['content-type']='application/ld+json; charset=utf-8'
         #    postResult = session.post(url = inboxUrl, data = postJsonStr, headers=headers)
         #    if not (postResult.status_code<200 or postResult.status_code>202):
         #        return True

+ 2 - 2
shares.py

@@ -392,7 +392,7 @@ def sendShareViaServer(baseDir,session, \
             postImage(session,imageFilename,[],inboxUrl.replace('/'+postToBox,'/shares'),headers,"inbox:write")
     
     headers = {'host': fromDomain, \
-               'Content-type': 'application/json', \
+               'Content-type': 'application/json; charset=utf-8', \
                'Authorization': authHeader}
     postResult = \
         postJson(session,newShareJson,[],inboxUrl,headers,"inbox:write")
@@ -473,7 +473,7 @@ def sendUndoShareViaServer(baseDir: str,session, \
     authHeader=createBasicAuthHeader(fromNickname,password)
     
     headers = {'host': fromDomain, \
-               'Content-type': 'application/json', \
+               'Content-type': 'application/json; charset=utf-8', \
                'Authorization': authHeader}
     postResult = \
         postJson(session,undoShareJson,[],inboxUrl,headers,"inbox:write")

+ 1 - 1
skills.py

@@ -151,7 +151,7 @@ def sendSkillViaServer(baseDir: str,session,nickname: str,password: str,
     authHeader=createBasicAuthHeader(Nickname,password)
      
     headers = {'host': domain, \
-               'Content-type': 'application/json', \
+               'Content-type': 'application/json; charset=utf-8', \
                'Authorization': authHeader}
     postResult = \
         postJson(session,newSkillJson,[],inboxUrl,headers,"inbox:write")

+ 4 - 3
tests.py

@@ -85,7 +85,7 @@ def testHttpsigBase(withDigest):
     os.mkdir(path)
     os.chdir(path)
 
-    contentType='application/activity+json'
+    contentType='application/activity+json; charset=utf-8'
     nickname='socrates'
     domain='argumentative.social'
     httpPrefix='https'
@@ -106,7 +106,7 @@ def testHttpsigBase(withDigest):
     dateStr=strftime("%a, %d %b %Y %H:%M:%S %Z", gmtime())
     boxpath='/inbox'
     if not withDigest:
-        headers = {'host': headersDomain,'date': dateStr,'content-type': 'application/json'}
+        headers = {'host': headersDomain,'date': dateStr,'content-type': 'application/json; charset=utf-8'}
         signatureHeader = \
             signPostHeaders(dateStr,privateKeyPem, nickname, \
                             domain, port, \
@@ -122,6 +122,7 @@ def testHttpsigBase(withDigest):
                             boxpath, httpPrefix, messageBodyJsonStr)
 
     headers['signature'] = signatureHeader
+    assert 'utf-8' in headers['content-type']
     assert verifyPostHeaders(httpPrefix,publicKeyPem,headers, \
                              boxpath,False,None, \
                              messageBodyJsonStr)
@@ -133,7 +134,7 @@ def testHttpsigBase(withDigest):
                              messageBodyJsonStr) == False
     if not withDigest:
         # fake domain
-        headers = {'host': 'bogon.domain','date': dateStr,'content-type': 'application/json'}
+        headers = {'host': 'bogon.domain','date': dateStr,'content-type': 'application/json; charset=utf-8'}
     else:
         # correct domain but fake message
         messageBodyJsonStr = '{"a key": "a value", "another key": "Fake GNUs", "yet another key": "More Fake GNUs"}'