0

I have a thttpd (http://acme.com/software/thttpd/) web-server on which I have images (svg) and JSON files.

I'm developping a small web page that needs to retrieves these resources from my web-server but I always get the following error :

No 'Access-Control-Allow-Origin' header is present on the requested resource.

I know that I have to set the Access-Control-Allow-Origin header on the server side to accept requests from any origin like in a .htaccess file on an Apache server :

Header set Access-Control-Allow-Origin *

But I really can't figure out how to do that on a thttpd server. All the documentation and related topics I've read so far are for Apache, NGINX, IIS6, ...

I have all the needed rights to modify the configuration files on the web-server (I have root access).

Note that I also tried to use "jsonp" as data type in my HTTP Request, in my Javascript code, but I get the following error while trying to retrieve my JSON file.

Uncaught SyntaxError: Unexpected token :

Anyway I also need to get images in SVG format so I would like to avoid using "jsonp" as data type.

Here's my javascript code :

31 $.ajax({
33   url: "http://ip_address/file.json",
34   dataType: "jsonp",                                                                                                                                                                             
35   crossDomain: true,
36   data: {
37     format: "json"
38   },
39   success: function(data) {
40     var json = $.parseJSON(data);
41     alert(data);
42   }
43 });

any help would be really appreciated !

Thanks

1 Answers1

0

In libhttpd.c you can update the response string to include

Change

"%.20s %d %s\015\012Server: %s\015\012Content-Type: %s\015\012Date: %s\015\012Last-Modified: %s\015\012Accept-Ranges: bytes\015\012Connection: close\015\012"

To

"%.20s %d %s\015\012Server: %s\015\012Content-Type: %s\015\012Date: %s\015\012Last-Modified: %s\015\012Accept-Ranges: bytes\015\012Access-Control-Allow-Origin: *\015\012Connection: close\015\012"

https://github.com/uoaerg/thttpd/blob/master/libhttpd.c#L652

Yossi Neiman
  • 815
  • 1
  • 7
  • 13