TheDJ has uploaded a new change for review.
https://gerrit.wikimedia.org/r/236076
Change subject: Make it possible for a format to fail with an HTTP error code
......................................................................
Make it possible for a format to fail with an HTTP error code
The purpose for this is to make sure that when serving up subtitle
files with the subtitle API (T111552), the browser will not attempt to
pointlessly parse the served files.
This is the most generic method I could come up with. In all instances
we return error 400 in case of error. Although technically this might
not be 100% correct, it will probably do.
The only thing this won't catch is if the params are not validating.
In that case the main module takes over and we never reach
a state where the response becomes TimedText 'specific'. Since we
control the url generation, this shouldn't really be a problem.
Change-Id: I11b2824c6725143cff5b4c56194f94c44ce451c0
---
M includes/api/ApiFormatBase.php
1 file changed, 13 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/76/236076/1
diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php
index f54f20f..e8c81f8 100644
--- a/includes/api/ApiFormatBase.php
+++ b/includes/api/ApiFormatBase.php
@@ -32,6 +32,7 @@
abstract class ApiFormatBase extends ApiBase {
private $mIsHtml, $mFormat, $mUnescapeAmps, $mHelp;
private $mBuffer, $mDisabled = false;
+ private $mFailWithHTTPError = false;
protected $mForceDefaultParams = false;
/**
@@ -171,6 +172,10 @@
}
$mime = $this->getMimeType();
+ $data = $this->getResult()->getResultData();
+ if ( $this->mFailWithHTTPError && isset( $data['error'] ) ) {
+
$this->getMain()->getRequest()->response()->statusHeader( 400 );
+ }
if ( $this->getIsHtml() && $mime !== null ) {
$format = $this->getFormat();
$lcformat = strtolower( $format );
@@ -257,6 +262,14 @@
$this->setWarning( "format=$name has been deprecated. Please
use format=json$fm instead." );
}
+ /**
+ * Configure the output to respond with an HTTP error status code.
+ * @param bool $fail
+ */
+ public function setFailWithHTTPError( $fail ) {
+ $this->mFailWithHTTPError = $fail;
+ }
+
/************************************************************************//**
* @name Deprecated
* @{
--
To view, visit https://gerrit.wikimedia.org/r/236076
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I11b2824c6725143cff5b4c56194f94c44ce451c0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: TheDJ <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits