Skip to content

Commit

Permalink
Removed /base64 endpoint (postmanlabs#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zinovii Dmytriv committed Aug 28, 2020
1 parent f8ec666 commit be874ac
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
44 changes: 22 additions & 22 deletions httpbin/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,28 +1287,28 @@ def generate_bytes():
return response


@app.route("/base64/<value>")
def decode_base64(value):
"""Decodes base64url-encoded string.
---
tags:
- Dynamic data
parameters:
- in: path
name: value
type: string
default: SFRUUEJJTiBpcyBhd2Vzb21l
produces:
- text/html
responses:
200:
description: Decoded base64 content.
"""
encoded = value.encode("utf-8") # base64 expects binary string as input
try:
return base64.urlsafe_b64decode(encoded).decode("utf-8")
except:
return "Incorrect Base64 data try: SFRUUEJJTiBpcyBhd2Vzb21l"
# @app.route("/base64/<value>")
# def decode_base64(value):
# """Decodes base64url-encoded string.
# ---
# tags:
# - Dynamic data
# parameters:
# - in: path
# name: value
# type: string
# default: SFRUUEJJTiBpcyBhd2Vzb21l
# produces:
# - text/html
# responses:
# 200:
# description: Decoded base64 content.
# """
# encoded = value.encode("utf-8") # base64 expects binary string as input
# try:
# return base64.urlsafe_b64decode(encoded).decode("utf-8")
# except:
# return "Incorrect Base64 data try: SFRUUEJJTiBpcyBhd2Vzb21l"


@app.route("/cache", methods=("GET",))
Expand Down
2 changes: 1 addition & 1 deletion httpbin/templates/httpbin.1.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h2 id="ENDPOINTS">ENDPOINTS</h2>
<li><code>/delete</code> Returns DELETE data</li>
<li><a href="{{ url_for('view_anything') }}" data-bare-link="true"><code>/anything</code></a> Returns request data, including method used.</li>
<li><code>/anything/:anything</code> Returns request data, including the URL.</li>
<li><a href="{{ url_for('decode_base64', value='aGVsbG8gd29ybGQNCg==') }}"><code>/base64/:value</code></a> Decodes base64url-encoded string.</li>
<!--<li><a href="{{ url_for('decode_base64', value='aGVsbG8gd29ybGQNCg==') }}"><code>/base64/:value</code></a> Decodes base64url-encoded string.</li>-->
<li><a href="{{ url_for('encoding') }}"><code>/encoding/utf8</code></a> Returns page containing UTF-8 data.</li>
<li><a href="{{ url_for('view_gzip_encoded_content') }}" data-bare-link="true"><code>/gzip</code></a> Returns gzip-encoded data.</li>
<li><a href="{{ url_for('view_deflate_encoded_content') }}" data-bare-link="true"><code>/deflate</code></a> Returns deflate-encoded data.</li>
Expand Down
12 changes: 6 additions & 6 deletions test_httpbin.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ def test_anything(self):
self.assertEqual(data['method'], 'GET')
self.assertTrue(response.data.endswith(b'\n'))

def test_base64(self):
greeting = u'Здравствуй, мир!'
b64_encoded = _string_to_base64(greeting)
response = self.app.get(b'/base64/' + b64_encoded)
content = response.data.decode('utf-8')
self.assertEqual(greeting, content)
# def test_base64(self):
# greeting = u'Здравствуй, мир!'
# b64_encoded = _string_to_base64(greeting)
# response = self.app.get(b'/base64/' + b64_encoded)
# content = response.data.decode('utf-8')
# self.assertEqual(greeting, content)

def test_post_binary(self):
response = self.app.post('/post',
Expand Down

0 comments on commit be874ac

Please sign in to comment.