-
Notifications
You must be signed in to change notification settings - Fork 292
#1998 WARC writer: WARC-Protocol header to follow WARC field proposals #2034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rzo1
merged 2 commits into
apache:main
from
sebastian-nagel:sc-1998-warc-protocol-header
Sep 13, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
core/src/test/java/org/apache/stormcrawler/protocol/okhttp/HttpProtocolHeadersTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to you under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.stormcrawler.protocol.okhttp; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
|
||
| import org.apache.storm.Config; | ||
| import org.apache.stormcrawler.Metadata; | ||
| import org.apache.stormcrawler.protocol.AbstractProtocolTest; | ||
| import org.apache.stormcrawler.protocol.ProtocolResponse; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** Tests the protocol metadata collected by the response interceptor. */ | ||
| class HttpProtocolHeadersTest extends AbstractProtocolTest { | ||
|
|
||
| /** | ||
| * Over an unencrypted connection there is no handshake, hence no TLS version and no cipher | ||
| * suite. The cipher suite header must be skipped entirely: OkHttp's {@code | ||
| * Response.Builder.header(...)} does not accept a null value. | ||
| */ | ||
| @Test | ||
| void plainHttpRequestStoresProtocolVersionButNoCipherSuite() throws Exception { | ||
| HttpProtocol protocol = new HttpProtocol(); | ||
| Config conf = protocolConfig(); | ||
| conf.put("http.store.headers", true); | ||
| protocol.configure(conf); | ||
|
|
||
| ProtocolResponse response = | ||
| protocol.getProtocolOutput("http://localhost:" + HTTP_PORT, Metadata.empty); | ||
|
|
||
| assertEquals(200, response.getStatusCode()); | ||
| Metadata metadata = response.getMetadata(); | ||
| assertEquals( | ||
| "http/1.1", | ||
| metadata.getFirstValue(ProtocolResponse.PROTOCOL_VERSIONS_KEY), | ||
| "The protocol version is expected to be stored for plain HTTP requests"); | ||
| assertNull( | ||
| metadata.getFirstValue(ProtocolResponse.CIPHER_SUITE_KEY), | ||
| "No cipher suite is expected without a TLS handshake"); | ||
| } | ||
|
|
||
| private Config protocolConfig() { | ||
| Config conf = new Config(); | ||
| conf.put("http.agent.name", "test"); | ||
| conf.put("http.agent.version", "1.0"); | ||
| conf.put("http.agent.description", "test"); | ||
| conf.put("http.agent.url", "http://test.example.com"); | ||
| conf.put("http.agent.email", "test@example.com"); | ||
| return conf; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -616,7 +616,14 @@ public byte[] format(Tuple tuple) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| metadata.getFirstValue( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ProtocolResponse.PROTOCOL_VERSIONS_KEY, this.protocolMDprefix); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (protocolVersions != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buffer.append("WARC-Protocol: ").append(protocolVersions).append(CRLF); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (String protocolVersion : StringUtils.split(protocolVersions, ',')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buffer.append("WARC-Protocol: ").append(protocolVersion.trim()).append(CRLF); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final String cipherSuites = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| metadata.getFirstValue(ProtocolResponse.CIPHER_SUITE_KEY, this.protocolMDprefix); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (cipherSuites != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buffer.append("WARC-Cipher-Suite: ").append(cipherSuites).append(CRLF); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
618
to
627
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Key rename, plus trimming/skipping empty tokens — the metadata value is user-visible and may well be written by another protocol implementation with spaces after the commas, which would produce an invalid
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buffer.append("WARC-Payload-Digest").append(": ").append(payloadDigest).append(CRLF); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TlsVersion.toString()yields the enum name (TLS_1_3), which is not one of the values listed in the field proposal — those aretls/1.0..tls/1.3(andssl/3.0). Mapping it here keeps_protocol_versions_in the registered vocabulary for every consumer, not just the WARC writer.CipherSuite.javaName()is also a bit more explicit than relying ontoString().with this helper next to
getNormalizedProtocolName(Protocol)(plusimport okhttp3.TlsVersion;):