Announcement

#1 2019-10-23 12:34:01

sridharb
Member
2015-03-07
25

Response in text/plain instead of application/json

Hi,

If I query the webservice with format=json, I expect the response to be in application/json. It is in text/plain. Is this correct?

Latest piwigo, php 5.6.40.

Regards,
Sridhar

Offline

 

#2 2019-10-27 20:09:38

cryopad
Member
Grenoble, France
2015-11-01
95

Re: Response in text/plain instead of application/json

Hi sridharb,

Replies are generally in JSON but it happens that they are in text/plain when the server encountered an error.


If you enjoy Piwigo for iOS…
➤ We would appreciate an AppStore review.
➤ Comments, suggestions ? Tell us on GitHub…
➤ Not yet available in your language ? Help us translate it…

Offline

 

#3 2019-10-28 01:22:56

erAck
Piwigo Team
2015-09-06
360

Re: Response in text/plain instead of application/json

Type text/plain also without error.


Running Piwigo at https://erack.net/gallery/

Offline

 

#4 2019-10-28 07:00:06

cryopad
Member
Grenoble, France
2015-11-01
95

Re: Response in text/plain instead of application/json

Could you please give an example which leads to a text/plain message and which is not due to a server error?


If you enjoy Piwigo for iOS…
➤ We would appreciate an AppStore review.
➤ Comments, suggestions ? Tell us on GitHub…
➤ Not yet available in your language ? Help us translate it…

Offline

 

#5 2019-10-28 10:15:03

erAck
Piwigo Team
2015-09-06
360

Re: Response in text/plain instead of application/json

Just try:

Code:

curl -sSi 'https://YOURGALLERY/ws.php?format=json&method=pwg.getVersion' | grep -E '^(Content-Type:|\{)'

Which is no wonder as include/ws_protocols/json_encoder.php has

Code:

  function getContentType()
  {
    return 'text/plain';
  }

Running Piwigo at https://erack.net/gallery/

Offline

 

#6 2019-10-29 19:28:38

cryopad
Member
Grenoble, France
2015-11-01
95

Re: Response in text/plain instead of application/json

I did not look into this detail beforehand and you are perfectly right. The content type should be application/json as described by RFC4627.

I have replaced 'text/plain' with 'application/json' in the file /include/ws_protocols/json_encoder.php and everything works fine with the iOS app awaiting for JSON data. However, web browsers have issues and loading the tools/ws.htm page returns an 'error when parsing JSON string'. So some work needs to be done to fix this issue before switching to 'application/json'.


If you enjoy Piwigo for iOS…
➤ We would appreciate an AppStore review.
➤ Comments, suggestions ? Tell us on GitHub…
➤ Not yet available in your language ? Help us translate it…

Offline

 

#7 2019-10-29 23:54:43

erAck
Piwigo Team
2015-09-06
360

Re: Response in text/plain instead of application/json

Would also be good to test with known JSON consumers of the API, though I only know an XML consumer.

The failure with tools/ws.htm seems to be due to jQuery.parseJSON(json) in function parsePwgJSON(json), if that's inevitable then changing the content-type isn't such a good idea as jQuery is widespread.


Running Piwigo at https://erack.net/gallery/

Offline

 

#8 2019-10-30 08:05:33

sridharb
Member
2015-03-07
25

Re: Response in text/plain instead of application/json

I am writing a json consumer and that's why I reported this problem.

I, now, have to force the response to be read in json format even though it is in text/plain. Fortunately, my json parser has an override to do the same.

But it would be good if the API returns the correct content-type even in cases of error.

Offline

 

Board footer

Powered by FluxBB

github twitter facebook google+ newsletter Donate Piwigo.org © 2002-2020 · Contact