2

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.

Amandasaurus
  • 31,471
  • 65
  • 192
  • 253

3 Answers3

4

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)
Dan Andreatta
  • 5,454
  • 2
  • 24
  • 14
1

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>
Tom O'Connor
  • 27,480
  • 10
  • 73
  • 148
0

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.

chmeee
  • 7,370
  • 3
  • 30
  • 43