jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/354878 )

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


Send queries via POST, not GET

There is a limit on the length of GET request, both client-side and
server-side. Sending all queries via GET requests means that long
queries cannot be run from the query service UI.

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 can vary across browsers and there is no
clear disadvantage to POST, we always send the query via POST. The
“SPARQL endpoint” link offered next to “Display” and “Download” still
contains the GET version, since a POST request cannot be expressed in a
single, copyable 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, 7 insertions(+), 3 deletions(-)

Approvals:
  jenkins-bot: Verified
  Thiemo Mättig (WMDE): Looks good to me, approved



diff --git a/wikibase/queryService/api/Sparql.js 
b/wikibase/queryService/api/Sparql.js
index 7710bc0..33cb8e0 100644
--- a/wikibase/queryService/api/Sparql.js
+++ b/wikibase/queryService/api/Sparql.js
@@ -127,12 +127,16 @@
        SELF.prototype.query = function( query ) {
                var self = this,
                        deferred = $.Deferred(),
-                       settings = { headers: { Accept: 
'application/sparql-results+json' } };
+                       settings = {
+                               headers: { Accept: 
'application/sparql-results+json' },
+                               data: 'query=' + encodeURIComponent( query ),
+                               method: 'POST'
+                       };
 
-               this._queryUri = this._serviceUri + '?query=' + 
encodeURIComponent( query );
+               this._queryUri = this._serviceUri + '?' + settings.data;
 
                this._executionTime = Date.now();
-               $.ajax( this._queryUri, settings ).done( function( data, 
textStatus, request ) {
+               $.ajax( this._serviceUri, settings ).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: merged
Gerrit-Change-Id: Ic770e25bb4bd2edf0008aeaf23447d412407c0f5
Gerrit-PatchSet: 3
Gerrit-Project: wikidata/query/gui
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to