Browse Source

[http] Support HTTP redirection

tags/v0.9.8
Michael Brown 16 years ago
parent
commit
272e6ddc30
1 changed files with 28 additions and 0 deletions
  1. 28
    0
      src/net/tcp/http.c

+ 28
- 0
src/net/tcp/http.c View File

138
 static int http_response_to_rc ( unsigned int response ) {
138
 static int http_response_to_rc ( unsigned int response ) {
139
 	switch ( response ) {
139
 	switch ( response ) {
140
 	case 200:
140
 	case 200:
141
+	case 301:
142
+	case 302:
141
 		return 0;
143
 		return 0;
142
 	case 404:
144
 	case 404:
143
 		return -ENOENT;
145
 		return -ENOENT;
180
 	return 0;
182
 	return 0;
181
 }
183
 }
182
 
184
 
185
+/**
186
+ * Handle HTTP Location header
187
+ *
188
+ * @v http		HTTP request
189
+ * @v value		HTTP header value
190
+ * @ret rc		Return status code
191
+ */
192
+static int http_rx_location ( struct http_request *http, const char *value ) {
193
+	int rc;
194
+
195
+	/* Redirect to new location */
196
+	DBGC ( http, "HTTP %p redirecting to %s\n", http, value );
197
+	if ( ( rc = xfer_redirect ( &http->xfer, LOCATION_URI_STRING,
198
+				    value ) ) != 0 ) {
199
+		DBGC ( http, "HTTP %p could not redirect: %s\n",
200
+		       http, strerror ( rc ) );
201
+		return rc;
202
+	}
203
+
204
+	return 0;
205
+}
206
+
183
 /**
207
 /**
184
  * Handle HTTP Content-Length header
208
  * Handle HTTP Content-Length header
185
  *
209
  *
222
 
246
 
223
 /** List of HTTP header handlers */
247
 /** List of HTTP header handlers */
224
 static struct http_header_handler http_header_handlers[] = {
248
 static struct http_header_handler http_header_handlers[] = {
249
+	{
250
+		.header = "Location",
251
+		.rx = http_rx_location,
252
+	},
225
 	{
253
 	{
226
 		.header = "Content-Length",
254
 		.header = "Content-Length",
227
 		.rx = http_rx_content_length,
255
 		.rx = http_rx_content_length,

Loading…
Cancel
Save