Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Apache and displaying source files
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
boniek
Guru
Guru


Joined: 26 Mar 2005
Posts: 373

PostPosted: Sat Sep 17, 2005 9:27 am    Post subject: Apache and displaying source files Reply with quote

I have local apache-2.0.54-r30 server and want to view source files (files with .c .c++ .h etc extension) inside of web browser. Can anyone give me a hint how to do it? TIA
_________________
[HOWTO]New freetype subpixel font rendering for lcd monitors
Back to top
View user's profile Send private message
ekutay
l33t
l33t


Joined: 30 Mar 2005
Posts: 636
Location: Berlin

PostPosted: Sat Sep 17, 2005 6:38 pm    Post subject: Reply with quote

If not otherwise configured and DefaultType text/plain is set and you do not want to beautify, you can point the browser on the URL of the file. :-)
_________________
-- erol
Back to top
View user's profile Send private message
boniek
Guru
Guru


Joined: 26 Mar 2005
Posts: 373

PostPosted: Sat Sep 17, 2005 7:51 pm    Post subject: Reply with quote

I don't know if I understand you correctly but typing URL of the file gives me download box. What I want is to display file inside browser (just as plain ASCII files without extension)
_________________
[HOWTO]New freetype subpixel font rendering for lcd monitors
Back to top
View user's profile Send private message
ekutay
l33t
l33t


Joined: 30 Mar 2005
Posts: 636
Location: Berlin

PostPosted: Sat Sep 17, 2005 8:26 pm    Post subject: Reply with quote

Eyeyey, I was not precise, sorry. Not the real file URL like /home/user/sources/project/include/myfile.h. The file must be served by apache otherwise the browser will try to load the file manually and offers you something of its choice, eg. download, open with editor and so on. If the apache delivers the file as text/plain, the browser will display the file as plain text, at least it should do.
Eventually you should be able to type http://localhost/sources/project/include/myfile.h in the addressbar of your browser, when, here in my little example, the sources directory is deployed in the document root of the webserver.
_________________
-- erol
Back to top
View user's profile Send private message
boniek
Guru
Guru


Joined: 26 Mar 2005
Posts: 373

PostPosted: Mon Sep 19, 2005 9:06 am    Post subject: Reply with quote

It's no go when I type http://localhost/foobar.c or whatever - it still pop ups download box
_________________
[HOWTO]New freetype subpixel font rendering for lcd monitors
Back to top
View user's profile Send private message
ekutay
l33t
l33t


Joined: 30 Mar 2005
Posts: 636
Location: Berlin

PostPosted: Mon Sep 19, 2005 9:43 am    Post subject: Reply with quote

What is printed when you do
Code:
grep "^DefaultType" /etc/apache2/httpd.conf

If it is application/octet-stream you could change this to "text/plain" if this suits. Alternatively you could add the file suffix to /etc/apache2/mime.types.
Set
Quote:
text/plain asc txt

to
Quote:
text/plain asc txt c h c++


Otherwise you could invent a small cgi script to accomplish that task, which would give you the option of beautifying the output.
_________________
-- erol
Back to top
View user's profile Send private message
boniek
Guru
Guru


Joined: 26 Mar 2005
Posts: 373

PostPosted: Mon Sep 19, 2005 11:40 am    Post subject: Reply with quote

My apache uses /etc/mime.types for mime configuration. What I did to make it work as I wanted was commenting out following lines in mentioned file:
Code:

#text/x-c++hdr    h++ hpp hxx hh
#text/x-c++src     c++ cpp cxx cc
#text/x-chdr        h
#text/x-csrc         c

modifying following line:
Code:

text/plain             asc txt text diff pot c h c++


and rebooting.
Thanks for help ekutay.
_________________
[HOWTO]New freetype subpixel font rendering for lcd monitors
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum