Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML response doesn't seem to work #19

Open
vectorialgradha opened this issue Mar 12, 2015 · 3 comments
Open

HTML response doesn't seem to work #19

vectorialgradha opened this issue Mar 12, 2015 · 3 comments
Labels

Comments

@vectorialgradha
Copy link

Hi.

Creating a mock server from scratch with a test method which should return HTML doesn't seem to work. The files are created but the server keeps saying the method doesn't exist when performing a request with a web browser. Here are the contents of the server files:

application.json:

{"resources": {"GET-test": {"category": ""}}}

test/GET_200.html:

<html><body>Hi</body></html>

test/GET_H_200.html empty.
access log:

{"status": 200, "headers": {"Accept-Language": "es-es", "Accept-Encoding": "gzip, deflate", "Connection": "keep-alive", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/7.1.3 Safari/537.85.12", "Host": "localhost:8888", "Cookie": "_xsrf=2|bf7b90b8|9517b3acf74d9614bd0baeb4690f7ac7|1425469503"}, "remote_ip": "::1", "time": "2015-03-12T10:19:43.243750", "request_time": 1.837015151977539, "response": {"body": "Api does't exists, <a href=\"/__manage/create?url_path=&method=GET&status_code=200&format=json\">create resource method</a>", "headers": [["Content-Type", "text/html"], ["Access-Control-Allow-Origin", "*"]], "status_code": 404}, "url_path": "/", "body": "", "method": "GET", "uri": "/"}
{"status": 200, "headers": {"Accept-Language": "es-es", "Accept-Encoding": "gzip, deflate", "Connection": "keep-alive", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/7.1.3 Safari/537.85.12", "Host": "localhost:8888", "Cookie": "_xsrf=2|bf7b90b8|9517b3acf74d9614bd0baeb4690f7ac7|1425469503", "If-None-Match": "\"bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f\""}, "remote_ip": "::1", "time": "2015-03-12T10:20:04.500854", "request_time": 0.7579326629638672, "response": {"body": "Api does't exists, <a href=\"/__manage/create?url_path=test&method=GET&status_code=200&format=json\">create resource method</a>", "headers": [["Content-Type", "text/html"], ["Access-Control-Allow-Origin", "*"]], "status_code": 404}, "url_path": "/test", "body": "", "method": "GET", "uri": "/test"}
{"status": 200, "headers": {"Accept-Language": "es-es", "Accept-Encoding": "gzip, deflate", "Connection": "keep-alive", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/7.1.3 Safari/537.85.12", "Host": "localhost:8888", "Cookie": "_xsrf=2|bf7b90b8|9517b3acf74d9614bd0baeb4690f7ac7|1425469503"}, "remote_ip": "::1", "time": "2015-03-12T10:20:04.680572", "request_time": 0.5021095275878906, "response": {"body": "Api does't exists, <a href=\"/__manage/create?url_path=test&method=GET&status_code=200&format=json\">create resource method</a>", "headers": [["Content-Type", "text/html"], ["Access-Control-Allow-Origin", "*"]], "status_code": 404}, "url_path": "/test", "body": "", "method": "GET", "uri": "/test"}

It seems that creating a json response with the HTML works, but then clients don't interpret the result as HTML.

@andy-maier
Copy link

I can confirm the same issue with another kind of XML (not HTML) in the response. JSON format for the response worked immediately, XML format did not and caused the resource not to be found. (This with the REST calls).
I am using mock-server 0.3.7 on Ubuntu 14.04 with Python 2.7.6.

@andy-maier
Copy link

Some further investigation shows that when defining a resource /foo for REST XML, it does work using the URL /foo.xml. So the issue seems to be that the .xml suffix is not processed correctly.

Grzegorz,
would you mind verifying that for your problem?

Andy

@andy-maier
Copy link

Some more investigation: The XML resources are looked up as JSON resources, by mistake. I debugged this up to the point where the Tornado code calls into its handler method for GET, which is defined as:
def get(self, path, format=DEFAULT_FORMAT):
on line 118 in mock_server/handlers.py. The Tornado code just passes in the path argument (which is the path as specified in the HTTP request URI), but no format argument. As a result, the default format "json" is used, which leads further down (lines 73 and 77 in mock_server/rest.py) to constructing file names with a .json suffix. Which are of course not found, because the files that exist have an .xml suffix.

It is not clear to me how the author intended the .xml format to be passed down; but it seems to me that the format cannot possibly be passed down by Tornado to the mock-server code, because Tornado only knows about the URIs and nothing about whether a particular URI maps to a JSON or XML formatted resource. So the whole idea of having a format argument in the tornado handler functions seems strange to me. Anyway, just my 2 cents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants