Lucas Werkmeister (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/354878 )

Change subject: Send long queries via POST, not GET
......................................................................

Send long queries via POST, not GET

There is a limit on the length of GET request, both client-side and
server-side. At some point, the query interface should switch from
sending queries via GET to POST, which carries no such restriction (at
least not one any query should hit).

The server-side limit, imposed by an nginx server on query.wikidata.org,
appears to be at 16334 bytes of query: a query of 16333 space characters
(sent via curl, without URL-encoding the space characters) results in a
parse error from BlazeGraph, a query of 16334 space characters results
in a 414 Request-URI Too Large error from nginx. (I suspect that the
real limit is 2^14 = 16384 bytes, also counting
`GET /bigdata/namespace/wdq/sparql?query=` and `HTTP/1.1\r\n`, which
seems to add up to 16384 bytes plus or minus some off-by-one errors.)

The client-side limit is less clear, but according to some experiments
appears to be 6167 bytes on both Firefox and Chromium, which corresponds
to 2035 spaces in the query as sent by the query service UI (which
encodes each space as %20, three bytes).

Since the client-side limit is lower than the server-side limit, we
switch to POST as soon as the full GET URL exceeds the client-side
limit of 6167 bytes. (Technically, String.length counts UTF-16 code
units, not bytes, but after URL encoding the query no multi-byte
characters or code units should be left in the URL.)

To test this behavior, it is useful to know that `printf %*s 10` prints
10 space characters to standard output. This can be used to quickly
generate strings of a certain length.

Change-Id: Ic770e25bb4bd2edf0008aeaf23447d412407c0f5
---
M wikibase/queryService/api/Sparql.js
1 file changed, 11 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/gui 
refs/changes/78/354878/1

diff --git a/wikibase/queryService/api/Sparql.js 
b/wikibase/queryService/api/Sparql.js
index 7710bc0..650389a 100644
--- a/wikibase/queryService/api/Sparql.js
+++ b/wikibase/queryService/api/Sparql.js
@@ -127,12 +127,21 @@
        SELF.prototype.query = function( query ) {
                var self = this,
                        deferred = $.Deferred(),
-                       settings = { headers: { Accept: 
'application/sparql-results+json' } };
+                       settings = { headers: { Accept: 
'application/sparql-results+json' } },
+                       response;
 
                this._queryUri = this._serviceUri + '?query=' + 
encodeURIComponent( query );
 
                this._executionTime = Date.now();
-               $.ajax( this._queryUri, settings ).done( function( data, 
textStatus, request ) {
+               if ( this._queryUri.length < 6167 ) {
+                       response = $.ajax( this._queryUri, settings );
+               } else {
+                       settings.method = 'POST';
+                       settings.data = { query: query };
+                       response = $.ajax( this._serviceUri, settings );
+               }
+
+               response.done( function( data, textStatus, request ) {
                        self._executionTime = Date.now() - self._executionTime;
 
                        if ( typeof data.boolean === 'boolean' ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/354878
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic770e25bb4bd2edf0008aeaf23447d412407c0f5
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/query/gui
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to