Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need to debug a XML-RPC application, which sends XML replies over HTTP. I have a sample XML reply (i.e. data from the server, sent to the client that isn't working), I'd like to debug my application. Ideally I'd like a simple HTTP server that will serve one file in reply to all requests. Someone requests /? Send them this file. Someone makes a post to /server/page.php with a certain cookie? Just send them this file. I don't care about multithreading, or security. I will only need to use this for a few hours to debug. I have root on the machine.

i.e. I'm hoping there's something as easy to use as this:

simple_http_server -p 12445 -f my_test_file

I'm aware of python's SimpleHTTPServer module, but I'm not sure how to make it work in this case.

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

If you have inetd installed, just create a script like (I made a mistake, the script is not needed)

#!/bin/bash
cat $1

then add the line to inetd.conf

http stream  tcp   nowait root  /bin/cat cat /some/other/dir/file.txt

With Python just extend the BaseHTTPServer.BaseHTTPRequestHandler class and define a do_GET method, then run as described in the documentation, e.g.

import BaseHTTPServer
class HTTPHandlerOne(BaseHTTPServer.BaseHTTPRequestHandler):
  def do_GET(self): self.wfile.write("test\r\n")

def run(server_class=BaseHTTPServer.HTTPServer,
        handler_class=BaseHTTPServer.BaseHTTPRequestHandler):
    server_address = ('', 8000)
    httpd = server_class(server_address, handler_class)
    httpd.serve_forever()

run(handler_class=HTTPHandlerOne)
share|improve this answer
add comment

You could add a mod_rewrite rule to an apache vhost that would rewrite all requests back to the file you want to serve.

<VirtualHost *:80>
ServerName onefilevhost.local

RewriteEngine On
RewriteRule ^/(.*)? http://onefilevhost.local/serve/this/file.txt
</VirtualHost>
share|improve this answer
add comment

You can do that with Sinatra quite easy. Install sinatra doing gem install sinatra and create a test_page.rb file like this:

require 'sinatra'

get '/*' do
  File.read('/server/page.php')
end

If you don't have $RUBYOPT=rubygems on your shell, add require 'rubygems' at the beginning.

You can run it with ruby test_page.rb. It will listen on port 4567 by default.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.