Skip to content

Commit

Permalink
openid_example.pl and authentication, and added JSON mime types
Browse files Browse the repository at this point in the history
  • Loading branch information
Anniepoo committed Mar 27, 2016
1 parent 8faabe7 commit bd55226
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions openid_example.pl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
:- use_module(library(http/thread_httpd)).
:- use_module(library(http/html_write)).
:- use_module(library(http/http_error)).
:- use_module(library(pprint)).

http:location(openid, root(openid), []).

Expand Down Expand Up @@ -161,8 +162,8 @@
* DEBUG *
*******************************/

:- http_handler(root(.), print_request, [prefix]).
% :- http_handler(root(.), print_request, [prefix]).

print_request(Request) :-
format('Content-type: text/plain~n~n'),
pp(Request).
print_term(Request).
15 changes: 15 additions & 0 deletions web.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,21 @@ handle_api(Request) :-
reply_json_dict(Solution).
----

There's one complication here. By default, the +http_read_json_dict/2+ is pretty strict about mime type, only accepting +application/json+ .

The problem is that actual browsers send various types. You can expand the list of types accepted with the multifile +json_type/1+ .

----
:- use_module(library(http/http_json)).

:- multifile http_json/1.

http_json:json_type('application/x-javascript').
http_json:json_type('text/javascript').
http_json:json_type('text/x-javascript').
http_json:json_type('text/x-json').
----

Communicating With The Server
-----------------------------

Expand Down

0 comments on commit bd55226

Please sign in to comment.