2 * Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi <http://quvi.sourceforge.net/>.
6 * This library is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
26 #include <curl/curl.h>
32 #include "lua/quvi/opts.h"
33 #include "lua/getfield.h"
34 #include "lua/setfield.h"
37 extern glong
c_reset_headers(_quvi_t
);
39 gint
l_quvi_http_header(lua_State
*l
)
41 gboolean croak_if_error
;
49 q
= (_quvi_t
) l_get_reg_userdata(l
, USERDATA_QUVI_T
);
54 s
= luaL_checkstring(l
, 1);
59 opts
= l_quvi_object_opts_new(l
, 2);
60 croak_if_error
= l_quvi_object_opts_croak_if_error(l
, opts
);
61 l_quvi_object_opts_free(opts
);
67 CURL
*c
= q
->handle
.curl
;
68 q
->http
.headers
= curl_slist_append(q
->http
.headers
, s
);
69 cc
= curl_easy_setopt(c
, CURLOPT_HTTPHEADER
, q
->http
.headers
);
72 cc
= c_reset_headers(q
);
76 g_string_printf(q
->status
.errmsg
, "%s", curl_easy_strerror(cc
));
77 q
->status
.rc
= QUVI_ERROR_CALLBACK
;
79 if (croak_if_error
== TRUE
)
80 luaL_error(l
, "%s", q
->status
.errmsg
->str
);
83 /* Return a table of results. */
86 l_setfield_s(l
, QO_ERROR_MESSAGE
, q
->status
.errmsg
->str
, -1);
87 l_setfield_n(l
, QO_QUVI_CODE
, q
->status
.rc
);
89 return (1); /* no. of returned values (a table) */
92 /* vim: set ts=2 sw=2 tw=72 expandtab: */