below is part of the web2py response, showing the request content. You can see web2py got the correct content type header, but still fail to decode the json payload in request.
{"foo": "bar"}
And
| env | : |
|
| http_connection | : | close |
| http_forwarded_request_uri | : | /examples/simple_examples/status/foo/bar.json |
| http_host | : | |
| http_http_x_forwarded_proto | : | http |
| http_https | : | off |
| http_user_agent | : | fake |
| http_x_forwarded_for | : | 107.23.xxx.xxx |
| http_x_forwarded_host | : | |
| http_x_forwarded_proto | : | http |
| http_x_forwarded_server | : | |
| http_x_forwarded_ssl | : | off |
| post_vars | : |
| vars | : |
| wsgi | : |
|
response.generic_patterns). In general, generic views are a development tool and typically should not be used in production. If you want some actions to use a generic view, list those actions in response.generic_patterns (discussed in more detail in the chapter on Services).is_json = (env.get('http_content_type', '')
or env.get('content_type', '')
)[:16] == 'application/json'
Thanks for trying to help Niphlod. More details so far.
Strangely, that problem does NOT exist when I test with http://web2py.com/examples/simple_examples/status
So I compare the output page between mine and the one from web2py.com, then I found something.
On my server's output, there are only TWO appearances of "application/json", one in request.env.content_type and another in request.wsgi.environ.CONTENT_TYPE.
On web2py.com's output, there are FOUR appearances of "application/json", they are request.env.content_type, request.env.http_content_type, request.wsgi.environ.CONTENT_TYPE, and request.wsgi.environ.HTTP_CONTENT_TYPE.
And turns out line 343 of parse_get_post_vars() uses only "http_content_type" to trigger the json support.http://code.google.com/p/web2py/source/browse/gluon/main.py
No wonder the symptom. So the next question is, what makes the request.env.http_content_type missing in my case? Is it somehow because my apache sits behind an nginx (a webfaction convention) so the request.is_local is always True (which is not the case of web2py.com)?
Or, shall we simply change that line 343 of gluon/main.py into this:
is_json = (env.get('http_content_type', '')
or env.get('content_type', '')
)[:16] == 'application/json'
Thoughts?
@derek and @dhmorgan: actually what Iceberg posted is fine, it's really a subtle bug that needs to be addressed as per the docs posted by out own omniscient Jonathan, that can happen with some particular (although allowed) server architectures.
@jonathan: before diving in rocket's own "patching of spec-breaking servers", is there any other header we need to address ?
ok, thanks for the additional explanation.
tl;dr: As we don't "want to support" any breaking-spec servers (+1 on that), the only thing to take care of is to rely for both content-type and content-length headers to be directly on env and not expecting them to be neither http_content_length nor http_content_type.
did I get that clear ?
On Thursday, August 1, 2013 9:03:34 PM UTC+2, Jonathan Lundell wrote:On 1 Aug 2013, at 11:51 AM, Niphlod <nip...@gmail.com> wrote:@derek and @dhmorgan: actually what Iceberg posted is fine, it's really a subtle bug that needs to be addressed as per the docs posted by out own omniscient Jonathan, that can happen with some particular (although allowed) server architectures.
@jonathan: before diving in rocket's own "patching of spec-breaking servers", is there any other header we need to address ?content_size is the other one in this category.A clarification, though: Rocket is not patching spec-breaking servers; it's just a server complying with the spec, which mandates content_type if the client has supplied one (which would optionally appear as http_content_type).A spec-breaking server would be one that does not include content_type when one is provided by the client.The bug is that web2py relies on http_content_type, even though the spec does not require the server to include it.My comment about working around a spec break is purely hypothetical, and applies to the case where the client provides Content-Type, and the server passes that along as http_content_type (as it should, but is not required to do) and does not also pass it as content_type (which it *is* required to do).
--
ok. so to be on the safe side if env.http_content_type and env.http_content_length are provided gluon.main should update the env accordingly, and then the code can happily always use env.content_length and env.content_type
--
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Our policy is that request.env is just the wsgi environment, without computed variables.
Perhaps this?if not request.env.content_type and request.env.http_content_type:request.content_type = request.env.http_content_typeelse:request.content_type = request.http_content_type
--
hold still a few hours, I'm going to submit a patch for request that uses lazy evaluation of vars (ala web3py): should be a good occasion to do a general cleanup of all those bits !?
--
Also, this might be a good opportunity for var laziness, depending on how it works. For json-rpc apps like mine, parsing incoming application/json payloads into vars is a complete waste of time.
it should have been. If you're still experiencing issues please post your findings.
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
On 12 Dec 2013, at 2:34 AM, Niphlod <nip...@gmail.com> wrote:it should have been. If you're still experiencing issues please post your findings.Do you recall what the issue was? I'm curious, because I have a 2.5.1 server at the moment serving up application/json.
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/nVb1gUv2af8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
@Niphlod yes it's exactly this.@Jonathan I am on 2.5.1 too and it works fine on my MAC OS X machine but once I go on a web2py running under apache, the header content_type is sent and web2py catches only http_content_typeI will post my findings if it's not fixed in 2.8.2. I plan to migrate next month...