Skip to content

Commit ab61ddb

Browse files
attilapirossquito
authored andcommitted
[SPARK-26118][WEB UI] Introducing spark.ui.requestHeaderSize for setting HTTP requestHeaderSize
## What changes were proposed in this pull request? Introducing spark.ui.requestHeaderSize for configuring Jetty's HTTP requestHeaderSize. This way long authorization field does not lead to HTTP 413. ## How was this patch tested? Manually with curl (which version must be at least 7.55). With the original default value (8k limit): ```bash # Starting history server with default requestHeaderSize $ ./sbin/start-history-server.sh starting org.apache.spark.deploy.history.HistoryServer, logging to /Users/attilapiros/github/spark/logs/spark-attilapiros-org.apache.spark.deploy.history.HistoryServer-1-apiros-MBP.lan.out # Creating huge header $ echo -n "X-Custom-Header: " > cookie $ printf 'A%.0s' {1..9500} >> cookie # HTTP GET with huge header fails with 431 $ curl -H cookie http://458apiros-MBP.lan:18080/ <h1>Bad Message 431</h1><pre>reason: Request Header Fields Too Large</pre> # The log contains the error $ tail -1 /Users/attilapiros/github/spark/logs/spark-attilapiros-org.apache.spark.deploy.history.HistoryServer-1-apiros-MBP.lan.out 18/11/19 21:24:28 WARN HttpParser: Header is too large 8193>8192 ``` After: ```bash # Creating the history properties file with the increased requestHeaderSize $ echo spark.ui.requestHeaderSize=10000 > history.properties # Starting Spark History Server with the settings $ ./sbin/start-history-server.sh --properties-file history.properties starting org.apache.spark.deploy.history.HistoryServer, logging to /Users/attilapiros/github/spark/logs/spark-attilapiros-org.apache.spark.deploy.history.HistoryServer-1-apiros-MBP.lan.out # HTTP GET with huge header gives back HTML5 (I have added here only just a part of the response) $ curl -H cookie http://458apiros-MBP.lan:18080/ <!DOCTYPE html><html> <head>... <link rel="shortcut icon" href="/static/spark-logo-77x50px-hd.png"></link> <title>History Server</title> </head> <body> ... ``` Closes apache#23090 from attilapiros/JettyHeaderSize. Authored-by: “attilapiros” <piros.attila.zsolt@gmail.com> Signed-off-by: Imran Rashid <irashid@cloudera.com>
1 parent c34c422 commit ab61ddb

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

core/src/main/scala/org/apache/spark/internal/config/package.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,12 @@ package object config {
570570
.stringConf
571571
.createOptional
572572

573+
private[spark] val UI_REQUEST_HEADER_SIZE =
574+
ConfigBuilder("spark.ui.requestHeaderSize")
575+
.doc("Value for HTTP request header size in bytes.")
576+
.bytesConf(ByteUnit.BYTE)
577+
.createWithDefaultString("8k")
578+
573579
private[spark] val EXTRA_LISTENERS = ConfigBuilder("spark.extraListeners")
574580
.doc("Class names of listeners to add to SparkContext during initialization.")
575581
.stringConf

core/src/main/scala/org/apache/spark/ui/JettyUtils.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,15 @@ private[spark] object JettyUtils extends Logging {
356356

357357
(connector, connector.getLocalPort())
358358
}
359+
val httpConfig = new HttpConfiguration()
360+
httpConfig.setRequestHeaderSize(conf.get(UI_REQUEST_HEADER_SIZE).toInt)
359361

360362
// If SSL is configured, create the secure connector first.
361363
val securePort = sslOptions.createJettySslContextFactory().map { factory =>
362364
val securePort = sslOptions.port.getOrElse(if (port > 0) Utils.userPort(port, 400) else 0)
363365
val secureServerName = if (serverName.nonEmpty) s"$serverName (HTTPS)" else serverName
364366
val connectionFactories = AbstractConnectionFactory.getFactories(factory,
365-
new HttpConnectionFactory())
367+
new HttpConnectionFactory(httpConfig))
366368

367369
def sslConnect(currentPort: Int): (ServerConnector, Int) = {
368370
newConnector(connectionFactories, currentPort)
@@ -377,7 +379,7 @@ private[spark] object JettyUtils extends Logging {
377379

378380
// Bind the HTTP port.
379381
def httpConnect(currentPort: Int): (ServerConnector, Int) = {
380-
newConnector(Array(new HttpConnectionFactory()), currentPort)
382+
newConnector(Array(new HttpConnectionFactory(httpConfig)), currentPort)
381383
}
382384

383385
val (httpConnector, httpPort) = Utils.startServiceOnPort[ServerConnector](port, httpConnect,

docs/configuration.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,14 @@ Apart from these, the following properties are also available, and may be useful
973973
<br /><code>spark.com.test.filter1.param.name2=bar</code>
974974
</td>
975975
</tr>
976+
<tr>
977+
<td><code>spark.ui.requestHeaderSize</code></td>
978+
<td>8k</td>
979+
<td>
980+
The maximum allowed size for a HTTP request header, in bytes unless otherwise specified.
981+
This setting applies for the Spark History Server too.
982+
<td>
983+
</tr>
976984
</table>
977985

978986
### Compression and Serialization

0 commit comments

Comments
 (0)