Error when omitting to read POST request body

19 views
Skip to first unread message

vladac...@gmail.com

unread,
May 26, 2014, 8:10:05 AM5/26/14
to swi-p...@googlegroups.com
Hi,

I've noticed that omitting to read the data in the body of a POST request causes the HTTP connection to be reset. For instance, the following code works fine:

:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_client)).

:- http_handler(root(hello_world), say_hi, []).

server(Port) :-
    http_server(http_dispatch, [port(Port)]).

say_hi(Request) :-
    open("TestFile.mdxml", write, Stream),
    http_read_data(Request, _, [to(stream(Stream))]),
    close(Stream),
    format('Content-type: text/plain~n~n'),
    format('Hello World!~n').


However, when commenting out the call to the http_read_data/3 predicate, the "Hello world!" message is no longer returned, and the connection is reset.

How can I avoid this if I am not interested in the contents of the POST request body (i.e. I don't need to read them), and would just like to return a message without reading the contents?

Thanks,
Vlad
Reply all
Reply to author
Forward
0 new messages