Skip to content

Commit

Permalink
ae.net.http.common: Add HttpRequest/HttpResponse.dup
Browse files Browse the repository at this point in the history
Just enumerate the fields, nothing fancy for now.
  • Loading branch information
CyberShadow committed Jan 11, 2024
1 parent 494bf51 commit 1984a59
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
43 changes: 43 additions & 0 deletions net/http/common.d
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ public:
{
return Clock.currTime() - creationTime;
}

/// For `dup`.
protected void copyTo(typeof(this) other)
{
other.protocol = protocol;
other.protocolVersion = protocolVersion;
other.headers = headers.dup;
other.data = data.dup;
other.creationTime = creationTime;
}
}

// TODO: Separate this from an URL type
Expand All @@ -99,6 +109,24 @@ public:
this.resource = url;
} ///

/// For `dup`.
protected void copyTo(typeof(this) other)
{
super.copyTo(other);
other.method = method;
other.proxy = proxy;
other._resource = _resource;
other._port = _port;
}
alias copyTo = typeof(super).copyTo;

final typeof(this) dup()
{
auto result = new typeof(this);
copyTo(result);
return result;
} ///

/// Resource part of URL (everything after the hostname)
@property string resource() const pure nothrow @nogc
{
Expand Down Expand Up @@ -663,6 +691,21 @@ public:
}
}
}

protected void copyTo(typeof(this) other)
{
other.status = status;
other.statusMessage = statusMessage;
other.compressionLevel = compressionLevel;
}
alias copyTo = typeof(super).copyTo;

final typeof(this) dup()
{
auto result = new typeof(this);
copyTo(result);
return result;
} ///
}

/// Sets headers to request clients to not cache a response.
Expand Down
21 changes: 13 additions & 8 deletions net/http/responseex.d
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,21 @@ public:
.cacheForever(headers);
}

/// Construct and return a copy of this `HttpResponseEx`.
HttpResponseEx dup()
/// For `dup`.
protected void copyTo(typeof(this) other)
{
auto c = new HttpResponseEx;
c.status = this.status;
c.statusMessage = this.statusMessage;
c.headers = this.headers.dup;
c.data = this.data.dup;
return c;
super.copyTo(other);
other.pageTokens = pageTokens.dup;
other.errorTokens = errorTokens.dup;
}
alias copyTo = typeof(super).copyTo;

final typeof(this) dup()
{
auto result = new typeof(this);
copyTo(result);
return result;
} ///

/**
Request a username and password.
Expand Down

0 comments on commit 1984a59

Please sign in to comment.