-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NIFI-13652 Added Range Header Handling for Content Download (#9172)
This closes #9172
- Loading branch information
1 parent
60e9918
commit 89c7579
Showing
15 changed files
with
905 additions
and
70 deletions.
There are no files selected for viewing
This file contains 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 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 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
45 changes: 45 additions & 0 deletions
45
...-api/src/main/java/org/apache/nifi/web/api/config/RangeNotSatisfiableExceptionMapper.java
This file contains 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,45 @@ | ||
/* | ||
* 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.nifi.web.api.config; | ||
|
||
import jakarta.ws.rs.core.MediaType; | ||
import org.apache.nifi.web.api.streaming.RangeNotSatisfiableException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.ext.ExceptionMapper; | ||
import jakarta.ws.rs.ext.Provider; | ||
|
||
/** | ||
* Map Range Not Satisfiable Exception to HTTP 416 Responses | ||
*/ | ||
@Provider | ||
public class RangeNotSatisfiableExceptionMapper implements ExceptionMapper<RangeNotSatisfiableException> { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(RangeNotSatisfiableExceptionMapper.class); | ||
|
||
@Override | ||
public Response toResponse(final RangeNotSatisfiableException exception) { | ||
logger.info("HTTP 416 Range Not Satisfiable: {}", exception.getMessage()); | ||
|
||
return Response.status(Response.Status.REQUESTED_RANGE_NOT_SATISFIABLE) | ||
.entity(exception.getMessage()) | ||
.type(MediaType.TEXT_PLAIN_TYPE) | ||
.build(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...work/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/streaming/ByteRange.java
This file contains 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,55 @@ | ||
/* | ||
* 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.nifi.web.api.streaming; | ||
|
||
import java.util.Objects; | ||
import java.util.OptionalLong; | ||
|
||
/** | ||
* Range of bytes requested as described in RFC 9110 Section 14.1.2 with optional first and last positions | ||
*/ | ||
public class ByteRange { | ||
private final Long firstPosition; | ||
|
||
private final Long lastPosition; | ||
|
||
public ByteRange(final Long firstPosition, final Long lastPosition) { | ||
if (firstPosition == null) { | ||
Objects.requireNonNull(lastPosition, "Last Position required"); | ||
} | ||
this.firstPosition = firstPosition; | ||
this.lastPosition = lastPosition; | ||
} | ||
|
||
/** | ||
* Get first position in byte range which can be empty indicating the last position must be specified | ||
* | ||
* @return First position starting with 0 or empty | ||
*/ | ||
public OptionalLong getFirstPosition() { | ||
return firstPosition == null ? OptionalLong.empty() : OptionalLong.of(firstPosition); | ||
} | ||
|
||
/** | ||
* Get last position in byte range which can empty indicating the first position must be specified | ||
* | ||
* @return Last position starting with 0 or empty | ||
*/ | ||
public OptionalLong getLastPosition() { | ||
return lastPosition == null ? OptionalLong.empty() : OptionalLong.of(lastPosition); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ifi-web-api/src/main/java/org/apache/nifi/web/api/streaming/ByteRangeFormatException.java
This file contains 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,27 @@ | ||
/* | ||
* 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.nifi.web.api.streaming; | ||
|
||
/** | ||
* Byte Range Format Exception indicating invalid units specified in Range Header | ||
*/ | ||
public class ByteRangeFormatException extends IllegalArgumentException { | ||
|
||
public ByteRangeFormatException(final String message) { | ||
super(message); | ||
} | ||
} |
Oops, something went wrong.