##// END OF EJS Templates
wireprotoserver: move responsetype() out of http handler...
Gregory Szorc -
r36089:341c886e default
parent child Browse files
Show More
@@ -170,48 +170,6 class webproto(baseprotocolhandler):
170 urlreq.quote(self._req.env.get('REMOTE_HOST', '')),
170 urlreq.quote(self._req.env.get('REMOTE_HOST', '')),
171 urlreq.quote(self._req.env.get('REMOTE_USER', '')))
171 urlreq.quote(self._req.env.get('REMOTE_USER', '')))
172
172
173 def responsetype(self, prefer_uncompressed):
174 """Determine the appropriate response type and compression settings.
175
176 Returns a tuple of (mediatype, compengine, engineopts).
177 """
178 # Determine the response media type and compression engine based
179 # on the request parameters.
180 protocaps = decodevaluefromheaders(self._req, r'X-HgProto').split(' ')
181
182 if '0.2' in protocaps:
183 # All clients are expected to support uncompressed data.
184 if prefer_uncompressed:
185 return HGTYPE2, util._noopengine(), {}
186
187 # Default as defined by wire protocol spec.
188 compformats = ['zlib', 'none']
189 for cap in protocaps:
190 if cap.startswith('comp='):
191 compformats = cap[5:].split(',')
192 break
193
194 # Now find an agreed upon compression format.
195 for engine in wireproto.supportedcompengines(self._ui,
196 util.SERVERROLE):
197 if engine.wireprotosupport().name in compformats:
198 opts = {}
199 level = self._ui.configint('server',
200 '%slevel' % engine.name())
201 if level is not None:
202 opts['level'] = level
203
204 return HGTYPE2, engine, opts
205
206 # No mutually supported compression format. Fall back to the
207 # legacy protocol.
208
209 # Don't allow untrusted settings because disabling compression or
210 # setting a very high compression level could lead to flooding
211 # the server's network or CPU.
212 opts = {'level': self._ui.configint('server', 'zliblevel')}
213 return HGTYPE, util.compengines['zlib'], opts
214
215 def iscmd(cmd):
173 def iscmd(cmd):
216 return cmd in wireproto.commands
174 return cmd in wireproto.commands
217
175
@@ -252,6 +210,46 def parsehttprequest(repo, req, query):
252 'handleerror': lambda ex: _handlehttperror(ex, req, cmd),
210 'handleerror': lambda ex: _handlehttperror(ex, req, cmd),
253 }
211 }
254
212
213 def _httpresponsetype(ui, req, prefer_uncompressed):
214 """Determine the appropriate response type and compression settings.
215
216 Returns a tuple of (mediatype, compengine, engineopts).
217 """
218 # Determine the response media type and compression engine based
219 # on the request parameters.
220 protocaps = decodevaluefromheaders(req, r'X-HgProto').split(' ')
221
222 if '0.2' in protocaps:
223 # All clients are expected to support uncompressed data.
224 if prefer_uncompressed:
225 return HGTYPE2, util._noopengine(), {}
226
227 # Default as defined by wire protocol spec.
228 compformats = ['zlib', 'none']
229 for cap in protocaps:
230 if cap.startswith('comp='):
231 compformats = cap[5:].split(',')
232 break
233
234 # Now find an agreed upon compression format.
235 for engine in wireproto.supportedcompengines(ui, util.SERVERROLE):
236 if engine.wireprotosupport().name in compformats:
237 opts = {}
238 level = ui.configint('server', '%slevel' % engine.name())
239 if level is not None:
240 opts['level'] = level
241
242 return HGTYPE2, engine, opts
243
244 # No mutually supported compression format. Fall back to the
245 # legacy protocol.
246
247 # Don't allow untrusted settings because disabling compression or
248 # setting a very high compression level could lead to flooding
249 # the server's network or CPU.
250 opts = {'level': ui.configint('server', 'zliblevel')}
251 return HGTYPE, util.compengines['zlib'], opts
252
255 def _callhttp(repo, req, proto, cmd):
253 def _callhttp(repo, req, proto, cmd):
256 def genversion2(gen, engine, engineopts):
254 def genversion2(gen, engine, engineopts):
257 # application/mercurial-0.2 always sends a payload header
255 # application/mercurial-0.2 always sends a payload header
@@ -284,8 +282,8 def _callhttp(repo, req, proto, cmd):
284
282
285 # This code for compression should not be streamres specific. It
283 # This code for compression should not be streamres specific. It
286 # is here because we only compress streamres at the moment.
284 # is here because we only compress streamres at the moment.
287 mediatype, engine, engineopts = proto.responsetype(
285 mediatype, engine, engineopts = _httpresponsetype(
288 rsp.prefer_uncompressed)
286 repo.ui, req, rsp.prefer_uncompressed)
289 gen = engine.compressstream(gen, engineopts)
287 gen = engine.compressstream(gen, engineopts)
290
288
291 if mediatype == HGTYPE2:
289 if mediatype == HGTYPE2:
General Comments 0
You need to be logged in to leave comments. Login now