Skip to content

Commit

Permalink
Merge pull request postmanlabs#50 from FlaPer87/master
Browse files Browse the repository at this point in the history
Robots Support and Simple Html response
  • Loading branch information
Kenneth Reitz committed Jun 29, 2012
2 parents 2299db8 + 62657b2 commit 4717027
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
31 changes: 29 additions & 2 deletions httpbin/core.py
Expand Up @@ -14,12 +14,12 @@

import newrelic.agent

from flask import Flask, Response, request, render_template, redirect, jsonify
from flask import Flask, Response, request, render_template, redirect, jsonify, make_response
from raven.contrib.flask import Sentry
from werkzeug.datastructures import WWWAuthenticate

from . import filters
from .helpers import get_headers, status_code, get_dict, check_basic_auth, check_digest_auth, H
from .helpers import get_headers, status_code, get_dict, check_basic_auth, check_digest_auth, H, ROBOT_TXT, ANGRY_ASCII
from .utils import weighted_choice
from .structures import CaseInsensitiveDict

Expand Down Expand Up @@ -51,6 +51,33 @@ def view_landing_page():
return render_template('index.html')


@app.route('/html')
def view_html_page():
"""Simple Html Page"""

return render_template('moby.html')


@app.route('/robots.txt')
def view_robots_page():
"""Simple Html Page"""

response = make_response()
response.data = ROBOT_TXT
response.content_type = "text/plain"
return response


@app.route('/deny')
def view_deny_page():
"""Simple Html Page"""
response = make_response()
response.data = ANGRY_ASCII
response.content_type = "text/plain"
return response
# return "YOU SHOULDN'T BE HERE"


@app.route('/ip')
def view_origin():
"""Returns Origin IP."""
Expand Down
15 changes: 15 additions & 0 deletions httpbin/helpers.py
Expand Up @@ -45,7 +45,22 @@
'X-Forwarded-Port'
)

ROBOT_TXT = """User-agent: *
Disallow: /deny
"""

ANGRY_ASCII ="""
.-''''''-.
.' _ _ '.
/ O O \\
: :
| |
: __ :
\ .-"` `"-. /
'. .'
'-......-'
YOU SHOUDN'T BE HERE
"""

def get_files():
"""Returns files dict from request context."""
Expand Down
3 changes: 3 additions & 0 deletions httpbin/templates/httpbin.1.html
Expand Up @@ -26,6 +26,9 @@ <h2 id="ENDPOINTS">ENDPOINTS</h2>
<li><a href="/digest-auth/auth/user/passwd"><code>/digest-auth/:qop/:user/:passwd</code></a> Challenges HTTP Digest Auth.</li>
<li><a href="/stream/20"><code>/stream/:n</code></a> Streams <em>n</em>–100 lines.</li>
<li><a href="/delay/3"><code>/delay/:n</code></a> Delays responding for <em>n</em>–10 seconds.</li>
<li><a href="/html"><code>/html</code></a> Renders an HTML Page</li>
<li><a href="/robots.txt"><code>/robots.txt</code></a> Returns some robots.txt rules</li>
<li><a href="/deny"><code>/deny</code></a> Denied by robots.txt file</li>
</ul>


Expand Down

0 comments on commit 4717027

Please sign in to comment.