Permalink
Browse files

Added ability to see a curl command to do a post in a bin.

  • Loading branch information...
1 parent c833607 commit dd9fcec041a60014cbee65919fe64dab08c7c4e7 @marc-hughes marc-hughes committed with Brandon Holtsclaw Jan 30, 2011
Showing with 23 additions and 0 deletions.
  1. +7 −0 models.py
  2. +9 −0 static/style.css
  3. +7 −0 templates/bin.html
View
@@ -60,6 +60,13 @@ class Post(db.Model):
def id(self):
return baseN(abs(hash(self.created)), 36)[0:6]
+ def curl_command( self ):
+ body_part = "-d \"%s\"" % self.body
+ headers_to_ignore = ["Host", "Content-Length", "Accept", "User-Agent" ]
+ headers = filter( lambda x: not x in headers_to_ignore, self.headers )
+ header_part = reduce( lambda x,y: "%s -H \"%s: %s\"" % (x,y, self.headers[y]) , headers, "")
+ return "curl %s %s" % (body_part, header_part)
+
def __iter__(self):
out = []
if self.form_data:
View
@@ -28,4 +28,13 @@ dd {
margin: 0 0 0 80px;
padding: 0 0 0.5em 0;
white-space: pre;
+}
+
+.curl_command {
+ margin-left: 10px;
+ margin-right: 10px;
+ border-style: dashed;
+ border-width: 1px;
+ padding: 5px;
+ font: 11px "Courier New", Courier, mono;
}
View
@@ -3,6 +3,7 @@
{% block header %}<link href="/{{ bin.name }}/feed" type="application/atom+xml" rel="alternate" title="Feed of PostBin {{ bin.name }}" />{% endblock %}
{% block content %}
<p>All POST requests to this URL are logged for you to see here, sorted newest to oldest.</p>
+ <p><a href="javascript:void(0)" onclick="$('.curl_command').toggle()">Toggle Curl Commands</a></p>
{% for post in posts %}
<div class="post">
<a href="#{{ post.id }}" title="A unique ID for this request">#{{ post.id }}</a> @
@@ -33,7 +34,13 @@
</td></tr>
{% endfor %}
</table>
+
+ <div class="curl_command">
+ {{post.curl_command}} http://your-url
+ </div>
+
</div>
+
{% endfor %}
<a href="/">&larr; Home</a>

0 comments on commit dd9fcec

Please sign in to comment.