Skip to content

Commit

Permalink
Added public imports to multipart module in request module, used deco…
Browse files Browse the repository at this point in the history
…deComponent in multipart.
  • Loading branch information
andrewlalis committed Jan 22, 2024
1 parent 4ef2c76 commit a20c57b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions source/handy_httpd/components/multipart.d
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private ulong parseElementHeaders(ref MultipartElement element, string content)
private void parseContentDisposition(ref MultipartElement element) {
import std.algorithm : startsWith, endsWith;
import std.string : split, strip;
import std.uri : decode;
import std.uri : decodeComponent;
if ("Content-Disposition" !in element.headers) {
throw new MultipartFormatException("Missing required Content-Disposition header for multipart element.");
}
Expand All @@ -226,11 +226,11 @@ private void parseContentDisposition(ref MultipartElement element) {
foreach (string part; cdParts) {
string stripped = strip(part);
if (startsWith(stripped, "name=\"") && endsWith(stripped, "\"")) {
element.name = decode(stripped[6 .. $ - 1]);
element.name = decodeComponent(stripped[6 .. $ - 1]);
traceF!"Element name: %s"(element.name);
} else if (startsWith(stripped, "filename=\"") && endsWith(stripped, "\"")) {
import std.typecons : nullable;
element.filename = nullable(decode(stripped[10 .. $ - 1]));
element.filename = nullable(decodeComponent(stripped[10 .. $ - 1]));
traceF!"Element filename: %s"(element.filename);
}
}
Expand Down
11 changes: 7 additions & 4 deletions source/handy_httpd/components/request.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import std.exception;
import slf4d;
import streams;

/// For convenience, provide access to multipart functionality.
public import handy_httpd.components.multipart : readBodyAsMultipartFormData, MultipartFormData, MultipartElement;

/**
* The data which the server provides to HttpRequestHandlers so that they can
* formulate a response.
Expand Down Expand Up @@ -44,7 +47,7 @@ struct HttpRequest {
/**
* A list of parsed query parameters from the request's URL.
*/
public StringMultiValueMap queryParams;
public const(StringMultiValueMap) queryParams;

/**
* An associative array containing any path parameters obtained from the
Expand Down Expand Up @@ -85,7 +88,7 @@ struct HttpRequest {
* Returns: True if this request has a header with the given name, or false
* otherwise.
*/
public bool hasHeader(string name) {
public bool hasHeader(string name) const {
return headers.contains(name);
}

Expand All @@ -96,7 +99,7 @@ struct HttpRequest {
* name = The name of the header, case-sensitive.
* Returns: The header's string representation, or null if not found.
*/
public string getHeader(string name) {
public string getHeader(string name) const {
return headers.getFirst(name).orElse(null);
}

Expand Down Expand Up @@ -129,7 +132,7 @@ struct HttpRequest {
* doesn't exist.
* Returns: The value of the URL parameter.
*/
public T getParamAs(T)(string name, T defaultValue = T.init) {
public T getParamAs(T)(string name, T defaultValue = T.init) const {
import std.conv : to, ConvException;
return this.queryParams.getFirst(name)
.map!((s) {
Expand Down

0 comments on commit a20c57b

Please sign in to comment.