Skip to content

Commit

Permalink
remote-curl: use post_rpc() for protocol v2 also
Browse files Browse the repository at this point in the history
When transmitting and receiving POSTs for protocol v0 and v1,
remote-curl uses post_rpc() (and associated functions), but when doing
the same for protocol v2, it uses a separate set of functions
(proxy_rpc() and others). Besides duplication of code, this has caused
at least one bug: the auth retry mechanism that was implemented in v0/v1
was not implemented in v2.

To fix this issue and avoid it in the future, make remote-curl also use
post_rpc() when handling protocol v2. Because line lengths are written
to the HTTP request in protocol v2 (unlike in protocol v0/v1), this
necessitates changes in post_rpc() and some of the functions it uses;
perform these changes too.

A test has been included to ensure that the code for both the unchunked
and chunked variants of the HTTP request is exercised.

Note: stateless_connect() has been updated to use the lower-level packet
reading functions instead of struct packet_reader. The low-level control
is necessary here because we cannot change the destination buffer of
struct packet_reader while it is being used; struct packet_buffer has a
peeking mechanism which relies on the destination buffer being present
in between a peek and a read.

Signed-off-by: Jonathan Tan <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
jonathantanmy authored and gitster committed Mar 3, 2019
1 parent 78ad917 commit a97d007
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 186 deletions.
2 changes: 1 addition & 1 deletion pkt-line.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void packet_buf_delim(struct strbuf *buf)
strbuf_add(buf, "0001", 4);
}

static void set_packet_header(char *buf, const int size)
void set_packet_header(char *buf, const int size)
{
static char hexchar[] = "0123456789abcdef";

Expand Down
1 change: 1 addition & 0 deletions pkt-line.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ void packet_delim(int fd);
void packet_write_fmt(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
void packet_buf_flush(struct strbuf *buf);
void packet_buf_delim(struct strbuf *buf);
void set_packet_header(char *buf, int size);
void packet_write(int fd_out, const char *buf, size_t size);
void packet_buf_write(struct strbuf *buf, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
void packet_buf_write_len(struct strbuf *buf, const char *data, size_t len);
Expand Down
Loading

0 comments on commit a97d007

Please sign in to comment.